Autofac: Batch registration of open-generic types

前端 未结 2 1040
[愿得一人]
[愿得一人] 2020-12-09 05:10

I got an assembly with many concrete types that implement IHandler, such as the following:

public class MoveCustomerHandler : IH         


        
2条回答
  •  死守一世寂寞
    2020-12-09 05:14

    In a similar style to Jim's answer but taking advantage of AsClosedTypesOf:

    Assembly[] assemblies = GetYourAssemblies();
    
    builder.RegisterAssemblyTypes(assemblies)
        .AsClosedTypesOf(typeof(IHandler<>));
    

提交回复
热议问题