Autofac: Batch registration of open-generic types

前端 未结 2 1033
[愿得一人]
[愿得一人] 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:20

    You probably want something like this, although I'm not sure how IsAssignable() behaves with open generics.

    Assembly[] assemblies = GetYourAssemblies();
    
    builder.RegisterAssemblyTypes(assemblies)
        .Where(t => t.IsAssignableFrom(typeof(IHandler<>)))
        .AsSelf()
        .AsImplementedInterfaces();
    

提交回复
热议问题