I've been doing some work with the Unity IoC container recently and had to configure some generic types so I thought I'd post some of the examples here so that I'd have some to refer back to more than anything else a blog post tends to be less likely to get lost that an old post-it note. Xml config to configure mapping for a specific generic type, note the use of [[]] to define the generic type. Inside the square brackets you specify type name and the assembly containing the type. In both example `1 signifies the generic parameter: <type type="Data.Repository.IRepository`1[[Poco.Address, Poco]], Data.Repository" mapTo="Data.Repository.LinqRepository`1[[Poco.Address, Poco]], Data.Repository"> <lifetime type="singleton"></lifetime> </type> Xml config to configure open generic type mapping: <typeAlias alias="IRepository`1" type="Questern.ActiveOrderManagementSystem.Data.Repository.IRepository`1, Questern.ActiveOrderManagementSystem.Data.Repository" /> <type type="IRepository`1" mapTo="Questern.ActiveOrderManagementSystem.Data.Repository.LinqRepository`1, Questern.ActiveOrderManagementSystem.Data.Repository"> <lifetime type="singleton" /> </type>
I've been doing some work with the Unity IoC container recently and had to configure some generic types so I thought I'd post some of the examples here so that I'd have some to refer back to more than anything else a blog post tends to be less likely to get lost that an old post-it note.
Xml config to configure mapping for a specific generic type, note the use of [[]] to define the generic type. Inside the square brackets you specify type name and the assembly containing the type. In both example `1 signifies the generic parameter:
<type type="Data.Repository.IRepository`1[[Poco.Address, Poco]], Data.Repository" mapTo="Data.Repository.LinqRepository`1[[Poco.Address, Poco]], Data.Repository"> <lifetime type="singleton"></lifetime> </type> Xml config to configure open generic type mapping:
<typeAlias alias="IRepository`1" type="Questern.ActiveOrderManagementSystem.Data.Repository.IRepository`1, Questern.ActiveOrderManagementSystem.Data.Repository" /> <type type="IRepository`1" mapTo="Questern.ActiveOrderManagementSystem.Data.Repository.LinqRepository`1, Questern.ActiveOrderManagementSystem.Data.Repository"> <lifetime type="singleton" /> </type>
Thanks to Marceli for helping out with this!!
.Net (4) ASP.Net (6) ASP.Net MVC (3) Best Practice (2) Book (4) Burn CD/DVD (1) C# (5) Career (2) Class Library (1) Community event (14) Design (1) Design Patterns (1) Ethernet (1) Home Network (1) i18n (1) Internet Explorer (1) iPod (1) JavaScript (2) jQuery (1) Library (1) Microsoft Translator (1) Ms Office (1) MVC Unit test (1) NWMTUG (6) Open Source (2) PowerShell (13) Python (1) SharePoint (1) SQL Server (1) Team System (1) Test Driven Development (7) Utility (14) Visual C++ (1) Visual Studio 2008 (11) Windows 64 bit (1) Windows 7 (10) Windows XP (3)