1

I found out about / added scrutor in one of my assemblies to test it out. I commented the original registrations and added a scan statement instead:

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;
}

But it appears to do nothing. During debug it immediately says that services are not registered. So I'm apparently missing something. When I debug and look in services I also do not see any of the services added.

edelwater
  • 2,650
  • 8
  • 39
  • 67
  • In which assembly do those implementations live? – Steven Dec 27 '21 at 14:10
  • In the assembly that is called. So the solution has around 50 assemblies and each has a static method AddXXX() which registers its services. So the executing assembly. – edelwater Dec 27 '21 at 14:23

1 Answers1

2

found the answer here: https://github.com/khellang/Scrutor/issues/92

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

works

edelwater
  • 2,650
  • 8
  • 39
  • 67