hello, my question is, is it a problem if I use dependency injection instance in the .application layer? Isn't the .application part backend?
merhaba sorunu sorum , .application katmanı içinde dependency injection instance alıp kullanmam bir sorun oluşturur mu? .application kısmı backend (arka taraf) değil mi?
12 Answer(s)
-
0
Hi @wcdagency
Could you ask your question in English ? If not, please contact [email protected] for futher assitance.
Thanks,
-
0
Merhaba, neden ingilizce sormamı istedin? neyse, My question is, is it ok to use dependency injection in application layer end use entity framework in it?
-
0
The support team helps you from different countries, that's why to communicate with them please write in English.
-
0
You can use dependency injection in application layer. If you check, you will see that we use it in a lot of places.
You should use generic repository
IRepository
in application layer to access your table. Otherwise some of our logics will not effect your db requests.See for more information: Documents/Repositories
-
0
-
0
You need to get the DbContext using the IDbContextProvider interface.
see https://github.com/aspnetboilerplate/aspnetboilerplate/issues/4059
-
0
If you want to get all courses you can do it with
_courseRepository
No need to injectDbContext
to yourAppService
(bad practise) -
0
thanks @maliming I am checking it out now.
hi alper, of course ,_courseRepository but I would like to use linq approach. I would need such
_courseCustomService.Courses.Where(x=>x.Id>3).tolist() ...
this is my aim.
-
0
also you can run LinQ queries on the repository class.
_courseRepository.GetAll().Where(x=>x.Name == "Test").FirstOrDefault();
GetAll()
allows you to run LinQ.See examples : https://github.com/aspnetzero/aspnet-zero-core/blob/a679d93a71d4aee20597f251407f6eda195e9b9c/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Application/Auditing/AuditLogAppService.cs#L98
-
0
hello alper
_courseRepository.GetAll().Where(x=>x.Name == "Test").FirstOrDefault();
.GetAll() returns IEnumerable or IQueryable, not .tolist() right? if so , .tolist() will very slow down the system .
-
0
GetAll
returnsIQueryable
e, which is a delayed query.I don't know why it causes performance problems. It doesn't query all entities into memory and then filter.
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/language-reference/query-execution
-
0
.GetAll()
returnsIQueryable