How to register all classes of a specific interface using the .net core default service container

In unity, I can register all interface types from the assembly using this method.

public static void RegisterTypes(IUnityContainer container) { container.RegisterTypes( AllClasses.FromLoadedAssemblies(). Where( type => typeof (IRunAtInit).IsAssignableFrom(type), WithMappings.FromAllInterfaces, WithName.TypeName); } 

Is it possible to implement this .net kernel this way using my own default service container?

+6
source share
1 answer

Try using the Scrutor extension: https://github.com/khellang/Scrutor

 services.Scan(scan => scan .FromAssemblyOf<IRunAtInit>() .AddClasses(classes => classes.AssignableTo<IRunAtInit>()) .AsImplementedInterfaces() .WithTransientLifetime()); 
0
source

All Articles