httpflow icon indicating copy to clipboard operation
httpflow copied to clipboard

How to adapt the clean approach when project uses stored procedures.

Open a-martynov opened this issue 4 years ago • 4 comments

Hi Steve, My question is : if the application I need to move from .net 4.8 (pretty big) to .net 6 does have data-access layer based on two hundred of stored procedures, and I cannot get rid of them, can I consider approach of clean architecture and your template but adapt it to work with some data-access code working with my old procedures ? So DB Context will be needed only for calling SPOCs (for crud operations).

My team and me are planning moving to new .net gradually and your advice would help us, thanks.

By the way, we are using N-tier architecture (controllers, services, data-access layers), our front end is via Angular(which won't be affected). Our stored procedures are mostly for optimisation purpose but having some logic inside them.

a-martynov avatar Dec 12 '21 18:12 a-martynov

Yes, though you'll probably have a much larger set of data access classes in your Infrastructure project than I show here by default. You might need a separate method to model every stored proc.

If you're looking for guidance on migrating from .NET 4.x to ASP.NET Core you may want to read this ebook:

https://docs.microsoft.com/en-us/dotnet/architecture/porting-existing-aspnet-apps/

This is also a process many teams enlist my company, NimblePros.com, to assist with.

Good luck!

ardalis avatar Dec 12 '21 21:12 ardalis

Great thanks!

a-martynov avatar Dec 18 '21 12:12 a-martynov

So are you recommending to add new method for each stored proc in IRepository?

laksh-parab avatar Dec 22 '21 20:12 laksh-parab

If necessary, or create logically grouped Query services/classes for that purpose. It depends a bit on the functionality of the SPROC how I would do it. Repositories should be just simple CRUD, at most with a specification to help shape the result. More complex operations that span many entities and/or aggregates should not be added to repositories but modeled as separate Query objects or services. Makes it easier to follow SOLID that way, especially SRP and OCP (and ISP) since you're not constantly adding to your repo interfaces/implementations.

ardalis avatar Dec 23 '21 04:12 ardalis