解决从给定接口派生的所有类-aspnetboilerplate

时间:2020-09-18 07:29:02

标签: c# castle-windsor aspnetboilerplate castle castle-dynamicproxy

我正在尝试解析从给定接口派生的所有类:

   public interface IScheduledAppService : IApplicationService
   {
      string Name { get; }
    
     // Other properties methods here
   }

想法是将几个类定义为:

 public class Dummy1ScheduledAppService : DataPumpAppServiceBase, IScheduledAppService, IDummy1ScheduledAppService 
 public class Dummy2ScheduledAppService : DataPumpAppServiceBase, IScheduledAppService, IDummy2ScheduledAppService 

...

然后用类似的方法解决它们:

 bootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));

            bootstrapper.Initialize();

            foreach (var service in bootstrapper.IocManager.ResolveAll<IScheduledAppService>())
            {
                Console.WriteLine($"{service.Name} ==> {service.IsEnabled}");                  
            }     

我尝试使用常规注册来注册它们,并且:

 IocManager.IocContainer.Register(
           Classes.FromAssembly(Assembly.GetExecutingAssembly())
               .IncludeNonPublicTypes()
               .BasedOn<IScheduledAppService>()
               .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
               .WithService.Self()
               .WithService.DefaultInterfaces()
               .LifestyleTransient()
           );

但是bootstrapper.IocManager.ResolveAll()不能解决任何问题。 我想这是预期的行为,但是我不知道如何获取和解析从IScheduledAppService派生的所有类。

谢谢!

0 个答案:

没有答案