lundi 27 septembre 2021

Can .NET Core Identity work with a Unit of Work Pattern?

I'm developing a .NET Core Web application (Razor Pages) with Entity Framework Core. I am implementing a Unit of Work (and generic repository) Design Pattern as I've had success with this in the past.

I would also like to use .NET Core Identity (Individual User Accounts) for authorisation/ authentication etc., but I'm wondering if .NET Core Identity might not integrate well with a Unit of Work Pattern.

Previously when using a Unit of Work and Generic Repository Pattern, I've only ever had one DbContext (Entity Framework) and this has been shared among multiple repositories within the same HTTP request.

If I retrofit .NET Core Identity into my Web Application an IdentityDbContext is created. This means I have 2 DbContexts in my application. The IdentityDbContext inherits from DbContext, so I could still use the IdentityDbContext, put my domain DbSet entities into it and then my UoW implementation would only have one DbContext. However, I would prefer to separate my domain entities from user authorisation/ authentication entities - it seems cleaner that way.

Another concern is that I think the ASP.NET Identity methods call SaveChanges() internally and when using a UoW pattern I usually only want that to happen once all the CRUD work is done.

I've researched this topic quite a bit on Stackoverflow and I feel like I am going around in circles!

Would really appreciate any guidance on whether this approach is advisable or best to avoid!

Thanks.

Aucun commentaire:

Enregistrer un commentaire