I am trying to register a generic type in a config file for Unity 2.0 but can't seem to get it right. I have been referring to the MS documentation here : http://msdn.microsoft.com/en-us/library/ff660933%28v=PandP.20%29.aspx#_Generic_Types
The code looks like this:
public interface IRepository<T> where T : class
{
...
}
public class GenericRepository<T> : IRepository<T> where T : class
{
...
}
public class BlogRepository : GenericRepository<BlogRepository>
{
...
}
The XML config i have at the moment loks like this:
<unity>
<!-- Aliases -->
<alias alias="BlogIRepository"
type="X.Services.Interfaces.IRepository[[X.Domain.Entities.Blog, X.Domain]], X.Services"/>
<alias alias="BlogRepository"
type="X.Repositories.BlogRepository, X.Repositories"/>
<!-- Type registration -->
<container name="development">
<!-- Common connection string value -->
<instance name="Conn" type="System.String" value="blahblahblah"/>
<register type="BlogIRepository" mapTo="BlogRepository">
<constructor>
<param name="connectionString" type="System.String" dependencyName="Conn"/>
</constructor>
</register>
</container>
</unity>
According to the documentation to register generic types you use square brackets around the generic type(s), and if the type is not a system type you provide the fully qualified type inside more square bracket. Which is what i have done, i think. Yet - no worky.
EDIT: Example from the MSDN site:
<register type="IDictionary[string, [MyApp.Interfaces.ILogger, MyApp]]"/>
The error generated is:
The type name or alias IRepository could not be resolved. Please check your configuration file and verify this type name.