Using Add with ForSingletonOf in StructureMap

50 views
Skip to first unread message

Neil Martin Patrao

unread,
Sep 27, 2017, 6:51:13 AM9/27/17
to structuremap-users

If have two classes Class1 and Class2 both implementing an interface IInterface.


And now if I need a singleton instance of each of these classes, would this be the right way to implement it?

c.ForSingletonOf<IInterface>().Use<Class1>().Named("Class1");
c.ForSingletonOf<IInterface>().Add<Class2>().Named("Class2");


And then getting the instances like this:

container.GetInstance<IInterface>("Class1");
container.GetInstance<IInterface>("Class2");


Is there anything wrong in this approach or is there a better approach?

Reply all
Reply to author
Forward
0 new messages