I love IoC mostly for its tooling to help with testing, particularly with tools like Moq. I want to employ these testing practices I have picked up over the years in a public library that 3rd party developers will use, however I am unsure on how to make the library consumable.
I have taken on the practice of using factories for my instantiation, which is a pattern that has worked well for past projects, but given that I was in control of the application, I could use the same container for the full application.
As I want to provide services from my library without direct instantiation via new
, or have my application consumers use my container, I am unsure as to how I can make this a smooth process.
One theory was to create public static
methods that wrap a resolved factory;
public static class MyObjectProvider
{
public static IMyObject CreateSomeObject(//args)
{
return Container.Resolve<IMyObjectFactory>().Create(//args);
}
}
whereby Container
is an internal static
reference. Although this is in essence a service locator pattern, I can't think of any way to go about it. With this the chain will be resolved by constructor injection, and the standard fare would apply herein.