Hi guys,

Got a DI question:

Say I have a class that has the following constructor:

public MyClass(IAnInterface a, IAnother b, IYetAnother c)...

In my startup.cs I have:

services.AddTransient<IAnInterface, AnInterfaceImplementation>();
...

That all works fine. DI will inject the correct implementations for each of
the interfaces in the constructors parameters.

BUT, now I want to be clever because the parameter list is growing too big
(forget SRP, this is a thought experiment). So I create:

public interface IHoldAllInterfaces{

IAnInterface AnInterface {get;}
...

}

Now MyClass just takes one parameter, the IHoldAllInterfaces
implementation, which internally has all of the other interfaces.

Is there a way that I can get MVC DI to resolve IHoldAllInterfaces so that
at runtime it will pass in an object that holds all of the internal
interfaces already resolved per the startup.cs file?

I hope this makes sense - I'm not very good at writing questions clearly
*and* concisely :)

Cheers
David

Reply via email to