Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 01, 2012 12:52 PM by BrockAllen
Member
55 Points
26 Posts
May 01, 2012 09:14 AM|LINK
Hi,
I just try out Unity in mvc app.
In the global.asax I do my setup code. I have this mapping:
container.RegisterType<IPlayer, Player>();
This mapping works in the Application.
Now I would like to switch to xml-mapping in the webconfig-file.
My web.config-part:
<configuration>
<configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections>
<unity>
<containers>
<container name="containerOne">
<types>
<!-- this is my Maping --> <type type="MvcApplication1.IPlayer" mapTo="MvcApplication1.Player" />
</types>
</container>
</containers> </unity>
But this Mapping don't work.
What is wrong?
Jens
212 Points
51 Posts
May 01, 2012 09:25 AM|LINK
check this link for a tutorial
http://blogs.msdn.com/b/miah/archive/2009/04/03/testing-your-unity-xml-configuration.aspx
All-Star
27526 Points
4903 Posts
MVP
May 01, 2012 12:52 PM|LINK
You also need to register the assembly that contains those types. I forget the syntax, but there's an <assembly> config element that you have to throw in there. You can also register a <namespace>.
storedproc
Member
55 Points
26 Posts
Unity with xml-configuration
May 01, 2012 09:14 AM|LINK
Hi,
I just try out Unity in mvc app.
In the global.asax I do my setup code. I have this mapping:
container.RegisterType<IPlayer, Player>();
This mapping works in the Application.
Now I would like to switch to xml-mapping in the webconfig-file.
My web.config-part:
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<unity>
<containers>
<container name="containerOne">
<types>
<!-- this is my Maping -->
<type type="MvcApplication1.IPlayer" mapTo="MvcApplication1.Player" />
</types>
</container>
</containers>
</unity>
But this Mapping don't work.
What is wrong?
Jens
chiragtoad
Member
212 Points
51 Posts
Re: Unity with xml-configuration
May 01, 2012 09:25 AM|LINK
check this link for a tutorial
http://blogs.msdn.com/b/miah/archive/2009/04/03/testing-your-unity-xml-configuration.aspx
BrockAllen
All-Star
27526 Points
4903 Posts
MVP
Re: Unity with xml-configuration
May 01, 2012 12:52 PM|LINK
You also need to register the assembly that contains those types. I forget the syntax, but there's an <assembly> config element that you have to throw in there. You can also register a <namespace>.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/