tags:

views:

22

answers:

1

I have problem when asking for default ILogger from Unity container. I have this setting defined in code (its VB.net)

Dim container As IUnityContainer
...
container.RegisterType(Of ILogger, NullLogger)()
container.RegisterType(Of ILogger, EntLibLogger)("EL")

When I am getting ILogger from container I may have different name, like:

 Ioc.Resolve(Of ILogger)("MyLogger")

However this raises error as the mapping is not set for 'MyLogger'. Can I force container to return type which was registered without name? Actually when I used setting from web.config it worked.

Any tips most welcome. Thanks. Cheers, X.

A: 

The registered instance is registered without a name, so it is not intended to be a default/fallback instance if no entry is found.

But you could write an extension for the container to hook into the resolving process. Or you could simply write an Extension-Method for the interface IUnityContainer which handles this fallback behavior.

Gerald Keider
Thanks for answer. I thought that Unity would handle this in some way. e.g. like StructureMap.
Xabatcha