Many place that i have read about static method they said please shouldn't use static method for access to database and should use dependency injection for inject other service and use that service to write other logic.But problem it happen when i inject AService in BService and inject AService in CService many month pass business logic is grow it make i need to inject BService in CService ,It make problem cause AService it already inject in two place can't do it. I try something like this for fix that solution.
public class InterlocutorFacade : GenericEFRepository<MsSql1DbContext, GenericUser>, IInterlocutorFacade
{
public InterlocutorFacade(MsSql1DbContext _msGenericDb) : base(_msGenericDb)
{
}
public async Task AddC()
{
await UserService.CreateLogs(_msGenericDb.Set<Logs>());
await _msGenericDb.SaveChangesAsync();
}
public async Task GetC()
{
var result = await UserService.GetFirstLogs(_msGenericDb.Set<Logs>());
}
}
and this is service is i use
public static class UserService
{
internal static async Task<Logs> GetFirstLogs(DbSet<Logs> dbSet)
{
var result = await dbSet.FirstOrDefaultAsync();
return result;
}
internal static async Task CreateLogs(DbSet<Logs> dbSet)
{
var result = await dbSet.AddAsync(new Logs() { });
}
}
But i not sure what problem will happen if i do it, have someone can show me a problem (etc performance , data conflict ) it will happen when i use this?