Answer the question
In order to leave comments, you need to log in
What's wrong with ASP.NET Identity in Onion architecture?
Decided it was time for me to try cool things like the Onion Repository+UnitOfWork architecture but I quite liked ASP.NET Identity which I would like to combine with this application architecture. I did not like the examples that were found on the net. For example , metanit.com/sharp/mvc5/23.10.php here the architecture of the layers is completely broken, namely:
- in the BLL the layer is connected to EntityFramework + Identity.EntityFramework
- in the DAL layer there is a bunch of business logic in the form of ApplicationRoleManager and ApplicationUserManager
and so on ...
Therefore, it was decided to make your own bike. To begin with, I took as an example a project that is generated when creating ASP.NET MVC with Identity already included and decided to repeat its functionality while spreading it into 3 layers.
Here's what happened:
https://github.com/dmitrievMV/OnionArchitectureWit...
In DAL:
- Entities.
- EF context
- Repository+UnitOfWork
- UserStore
All implementations in the assembly are private except UnitOfWork and UserStore. UserStore takes a UOW constructor and works with repositories. Only interfaces look outside. The structure of the database completely repeats the example from the small ones, except that the main keys are int.
In BLL:
-ApplicationUserManager
In WEB
-ApplicationSignInManager
Actually please help, spend a little time, just inspect the code. Answer a couple of questions:
-Have I implemented the Repository + UnitOfWork
correctly -Is the Dispose implemented correctly
-Which layer do you think ApplicationSignInManager should be in, because it uses OWIN and works with ApplicationUserManager
-Due to the fact that no layer except DAL knows about the database and orm, I decided to make connectionString a constant, is this a normal approach?
-Does it make sense to move the entities into a separate project and separate them from the annotations for the database?
-In the example, in the owin context, they put the ef context in this way app.CreatePerOwinContext(ApplicationDbContext.Create); how justified is this and is it worth it?
-In the implementation of UserStore for EF, they behave very strangely with dispose and I have a feeling that some data hangs in memory all the time, is that so?
How justified is such a bike?
Answer the question
In order to leave comments, you need to log in
Good afternoon!
Well, as far as I know, there are many implementations of UnitOfWork + Repository, and each of them has its own advantages and disadvantages. At you everything looks rather efficient and unit-testable.
I guess, yes. Only here private fields are private for that, in order to encapsulate them. I consider it very wrong that your disposed variable has a public modifier. I also saw somewhere on the net that it is recommended to explicitly assign null to the db variable after calling db.Dispose():
if (_db != null)
{
_db.Dispose();
_db = null;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question