Have Scrutor scan executing assembly

817 Views Asked by At

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.

1

There are 1 best solutions below

0
edelwater On

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