samedi 27 juillet 2019

.NET Core DI, injecting runtime generated class

In a .NET core application I'm using Microsoft's dependency container to register dependencies.

I want to know if it is possible to inject a derived type generated at runtime, even if the registration is that of the base type.

so

If I have something like this

pulic interface I
{
}

public class C1 : I
{
}

and the registration

sercices.AddSCoped<I, C1>();

when used

public class SomeCaller
{
     public SomeCaller(I instance) { } 
}

instead of injecting a C1 instance, I would like to inject a C1Proxy instance which was runtime generated.

Not looking to use an existing solution when it comes to the dependency container, I want to stick with what Microsoft provides.





Aucun commentaire:

Enregistrer un commentaire