Scrutor doesn't scan files from different sub projects

567 Views Asked by At

I have the following structure for my project:

firstProj
|
+--- src
|    |
|    +--- Repositories
|         |
|         +--- MyFirstRepository.cs
|         +--- IMyFirstRepository.cs
|
secondProj
|
+--- src
     |
     +--- Repositories
          |
          +--- MySecondRepository.cs   
          +--- IMySecondRepository.cs 

The firstProject contains a Startup.cs file, that has the following:

 services.Scan(scan => scan
     .FromEntryAssembly()
     .AddClasses(classes => classes
        .InNamespaces("my.namespaces"))
   .UsingRegistrationStrategy(RegistrationStrategy.Replace(ReplacementBehavior.ImplementationType))
   .AsImplementedInterfaces()
   .WithScopedLifetime());

The first repository is recognized and added to the pool, however, the second one doesn't. Both repositories are under my.namespace namespace, and if I manually add the first file:

services.AddScoped<IMyFirstRepository, MyFirstRepository>()

it works. Any ideas on how to make Scrutor scan all files?

1

There are 1 best solutions below

0
WiSH On

try this

   builder.Services.Scan(scan =>
            scan.FromAssemblies()
                .AddClasses(classes => classes.InNamespaces("Repositories"))
                .AsSelf()
                .WithScopedLifetime());