I am trying to get a reference to my container in a static class within my domain so that I can do something like this:
public static class DomainEvents
{
public static IUnityContainer Container { get; set; }
// ...
public static void Do<T>(T args) where T : IMyInterface
{
foreach (var s in Container.ResolveAll<IDoSomething<T>>())
s.DoSomething(args);
}
}
I obviously cannot inject it via constructor, is there any other way I can get a handle to it so I can resolve they registrations? Reading through some of the docs hasn’t really been helpful. Any assistance would be appreciated.
Why don’t you just pass container in as a parameter to the function? Or even better, this looks like a good candidate for an extension method. If you change the function header as below, then you should be able to call Do directly on the container. ie: container.Do(args);