-
Notifications
You must be signed in to change notification settings - Fork 39
Key based resolving
moodmosaic edited this page Jul 16, 2011
·
1 revision
Sometimes you need to register more than one implementations of an interface. Later in the application, in order to resolve a component instance you need to request it by key. Prior to support that in Agatha's container abastraction you had to reference directly the underlying container (which was frustrating in many cases).
Using the container of your choice (for ex. Windsor) register the components specifying a key:
container.Register(Component.For<RequestA>().Named("KeyForRequestA"));
container.Register(Component.For<RequestB>().Named("KeyForRequestB"));
Then later in the application, using Agatha's container abstration:
var requestA = IoC.Container.Resolve<RequestA>("KeyForRequestA");
var requestB = IoC.Container.Resolve<RequestB>("KeyForRequestB");