unitycontainer/documentation

Default\Expected behavior when named instance resolution fails or named instance is not found

manums opened this issue · 0 comments

We have a scenario in our project where we Register an interface type with different instances with different name. We also have a register for same interface type without any name.

We need to find out what is the expected behavior When Resolve fails to find any registered instance with given name. Especially in below case where we have another named instanced registered for same interface type IEventPublisher

Documentation for named registrations does not explicitly mention what is the default behavior in such cases.

Example:

container.Register<IEventPublisher>( "ChangeFeed", LifetimeType.Singleton, changeFeedObject);
container.Register<IEventPublisher>( null, LifetimeType.Singleton, changeFeedObject);

// later
var notExistingPublisher = container.Resolve<IEventPublisher>( "nonExistingName" );