I'm using Autofac and EF6.
I have a service which I would like to use with dbContext or with local collection. I've already tried to use InMemoryDatabase and inject it in a service, but I need to load all related entites due to validation rules and it'll lead to performance issues.
Is any way to solve this issue without creating the same service, but for local store (in such way I'll need to edit the logic in both of them and can lead to different behaviour)?
The goal of this is to preload in some cases all data and use local store, accessing multiple times to db context cause low performance.
Example of service:
public class ProductServiceDb {
private readonly IDbContext _db;
public ProductServiceDb(IDbContext db) {
_db = db;
}
public List<Product> GetAvailable()
{
return _db.Products.Where(_=>_.InStock).AsNoTracking().ToList();
}
}
public class ProductServiceLocal {
public List<Product> Products {get; set;}
public List<Product> GetAvailable()
{
return Products.Where(_=>_.InStock).ToList();
}
}
Also I've already thought about local data, but in such way I need to check in all methods if it's local data and use Local property then.