Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross Cutting Layer | Automapper | Dependency Injection

I have a MVC layered application and I have some questions about Cross Cutting layer. So far this layer has Logging, DI, Error Handling and Cache.

I created a project and put all those features separated by folder. Is this ok? Or should I create a project for each feature?

Because I set up Autofac (DI folder) in this project I had to add references to the other projects: Model, Repository and Service. Is it ok to add those references to Cross Cutting project?

Should I create a separated project to group common functionalities? For example Enums, Constants and methods like GetMd5Hash. Or should I use Cross Cutting project for that?

Should I consider Automapper as a Cross Cutting Concern? So far I set up it in the Presentation layer, to convert from Entity to ViewModel and ViewModel to Entity. Because of that, I had to add a reference to Model which I'd like to avoid.

like image 606
Yuri Cardoso Avatar asked Oct 19 '22 08:10

Yuri Cardoso


1 Answers

Normally, you have Cross cutting concerns (CCC) helpers which are being used throughout your application. These helpers could be defined in a single or different projects. I personally ask myself these 2 questions before deciding on granularity of my libraries :

1- Is A kind of related to B? Can I put them in 1 category (such as CCC) ?

2- Is there any case that I need to use A without B (or vise versa) in another project?

If answer to the first question is Yes and to the second is no then put them in the same library/package.And always consider reusability when you wanna decide on putting stuff on different projects.

These helpers are not supposed to have references to your main projects, as they're just helpers and utilities and should be business logic and business domain agnostic.

In your main projects (MVC app or Business Logic Layer's libraries) you're going to use these helpers throughout your code.Or you're going to use Aspect Oriented (AOP) libraries to inject them in your code.

I wouldn't consider things like DI and automapper as cross cutting concerns. Logging, auditing, authentication, authorization and caching are good examples of CCC. But things like DI and Automapper are the stuff you use to implement your architecture patterns and design, so they're different. And there is no point to create new libraries or helpers to apply them in your project.

like image 115
akardon Avatar answered Oct 30 '22 16:10

akardon