C
C#7mo ago
kyro

Shared Scrutor code across multiples solutions

hi there, i'm trying to share code of my DI container across two solutions, i'm actually using scrutor for scanning all the services with the given dependency, the thing is that if the code is brought into my shared solution no interface get scanned through scrutor, is there anyway to solve this?
public IServiceCollection ScanServices()
{
if (_serviceCollection is null)
{
throw new NullReferenceException("ServiceCollection is null");
}

Console.WriteLine($"GetEntryAssembly() {Assembly.GetEntryAssembly().FullName}");
Console.WriteLine($"GetExecutingAssembly() {Assembly.GetExecutingAssembly().FullName}");
Console.WriteLine($"GetCallingAssembly() {Assembly.GetCallingAssembly().FullName}");

return _serviceCollection
.AddSingleton(sp => sp)
.Scan(scan => scan
.FromCallingAssembly()
.AddClasses(classes => classes.AssignableTo<ISingleton>())
.AsSelfWithInterfaces()
.WithSingletonLifetime()
)
.Scan(scan => scan
.FromCallingAssembly()
.AddClasses(classes => classes.AssignableTo<ITransient>())
.AsSelfWithInterfaces()
.WithTransientLifetime()
);
}
public IServiceCollection ScanServices()
{
if (_serviceCollection is null)
{
throw new NullReferenceException("ServiceCollection is null");
}

Console.WriteLine($"GetEntryAssembly() {Assembly.GetEntryAssembly().FullName}");
Console.WriteLine($"GetExecutingAssembly() {Assembly.GetExecutingAssembly().FullName}");
Console.WriteLine($"GetCallingAssembly() {Assembly.GetCallingAssembly().FullName}");

return _serviceCollection
.AddSingleton(sp => sp)
.Scan(scan => scan
.FromCallingAssembly()
.AddClasses(classes => classes.AssignableTo<ISingleton>())
.AsSelfWithInterfaces()
.WithSingletonLifetime()
)
.Scan(scan => scan
.FromCallingAssembly()
.AddClasses(classes => classes.AssignableTo<ITransient>())
.AsSelfWithInterfaces()
.WithTransientLifetime()
);
}
if the same code is brought to my execution assembly works otherwise the interfaces wont get scanned
1 Reply
kyro
kyroOP7mo ago
(sorry for the paste)
Want results from more Discord servers?
Add your server