I have a Console app that depends on different projects (I use DependsOn() notation) in my console module.
[DependsOn(
typeof(AbpAutofacModule),
typeof(SecondProjectModule),
// Other dependencies
)]
public class MyConsoleAppModule...
Then, my console app calls a method in the second project and there I try to get an IRepository using the service provider like this:
using (var scope = SecondProjectModule.GetScope())
{
using (var uow = scope.ServiceProvider.GetService<IUnitOfWorkManager>().Begin())
{
var repo = scope.ServiceProvider.GetService<IReadOnlyRepository<MyEntity>>();
return ... // LINQ here
}
}
But the repo is empty with null for DbContext and other properties. If I call this method using my WebApp project it runs perfectly.
The GetScope() method in the SecondProjectModule is very simple:
public static IServiceScope GetScope(IServiceProvider serviceProvider = null)
{
var provider = serviceProvider ?? _serviceProvider;
return provider?
.GetRequiredService<IHybridServiceScopeFactory>()
.CreateScope();
}
Not sure where is the issue here since the dependencies from my ConsoleApp projects seems to be fine.