You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am fascinated by this project and I would like to use it as a model for a project with a Blazor front-end. I am studying the project's architecture. It is interesting but I have a question:
Unfortunately, (actually) EFCore doesn't fit well with Blazor. As you can see here, the first time you have at least two async methods that interact with EFCore, it will crash because it doesn't manage multi request in the same DbContext instance. So, to solve this problem I had to change the lifetime of EFCore from Scoped (default) to Transient. This has a big side effect: every time you ask for an instance that has a DbContext dependency, the DI Container will create a new instance of DbContext and so the change tracker will be empty. Take the following code from DepositUseCase
If EFCore lifetime is set to Transient then _customerService, _accountService, and _unitOfWork have 3 different instances of DbContext so 3 different instances of change tracker. So, when we run this._unitOfWork.Save() it will not save anything because its internal change tracker didn't register any changes.
The text was updated successfully, but these errors were encountered:
Hi,
I am fascinated by this project and I would like to use it as a model for a project with a Blazor front-end. I am studying the project's architecture. It is interesting but I have a question:
Unfortunately, (actually) EFCore doesn't fit well with Blazor. As you can see here, the first time you have at least two async methods that interact with EFCore, it will crash because it doesn't manage multi request in the same DbContext instance. So, to solve this problem I had to change the lifetime of EFCore from Scoped (default) to Transient. This has a big side effect: every time you ask for an instance that has a DbContext dependency, the DI Container will create a new instance of DbContext and so the change tracker will be empty. Take the following code from DepositUseCase
If EFCore lifetime is set to Transient then _customerService, _accountService, and _unitOfWork have 3 different instances of DbContext so 3 different instances of change tracker. So, when we run
this._unitOfWork.Save()
it will not save anything because its internal change tracker didn't register any changes.The text was updated successfully, but these errors were encountered: