1

我发现/在我的一个程序集中添加了 scrutor 来测试它。我评论了原始注册并添加了扫描语句:

public static IServiceCollection AddTestThing(this IServiceCollection services
     , IConfiguration configuration) {

  // services.AddTransient<IExampleService, ExampleService>();
  // services.AddTransient<IA_B, A_B>();
  // services.AddTransient<IA_C, A_C>();
  // services.AddTransient<ID_A, D_A>();

  services.Scan(scan => scan
        .FromExecutingAssembly()
        .AddClasses()
        .UsingRegistrationStrategy(RegistrationStrategy.Skip)
        .AsImplementedInterfaces()
        .WithTransientLifetime());

  return services;
}

但它似乎什么也没做。在调试期间,它立即说服务未注册。所以我显然错过了一些东西。当我调试和查看服务时,我也看不到任何添加的服务。

4

1 回答 1

1

在这里找到了答案:https ://github.com/khillang/Scutor/issues/92

     services.Scan(scan => scan
      .FromAssemblies(Assembly.GetExecutingAssembly())
      .AddClasses()
      .UsingRegistrationStrategy(RegistrationStrategy.Skip)
      .AsMatchingInterface()
      .WithTransientLifetime());

作品

于 2021-12-27T15:15:29.230 回答