I have an MVC application that consists of 3 projects Core, Repository & Web.
References are as follows:
My ViewModels sit in the Web project, which are being used by controllers.
In the Core project I have an email class that I want to recieve the bound ViewModel object as a parameter (to send an HTML email of the record).
The problem is that I can't use that object as a parameter in the email method as it will create a circular dependency.
Any ideas how I can have that object in 2 projects at once??
It sounds like the view model is holding domain information, which it shouldn't be doing. Specifically, it represents a structure of data which belongs in Core because Core has functionality that needs it.
Two main approaches to this are:
In either case, if you have a model that belongs in core then build it there.
What is that model? I really can't know for sure based on the description. For now I'm going to call it an EmailTemplate
. In that case it sounds like you have this:
Core Assembly
Email Object
Send Method (View Model parameter)
Web Assembly
View Model Object
properties
Instead, you'd want this:
Core Assembly
Email Object
Send Method (Email Template parameter)
Email Template Object
Web Assembly
View Model Object
Email Template property
In fact, you might not even need a view model at all and just bind the view to the domain object. But that's really tough to say without knowing more.
As you're discovering, dependencies should only ever point inward to the domain core. (In fact, the Repository references are also backwards, but that's outside the scope of the question.) Either the functionality and the structures to support it belong in Core, or the functionality itself belongs in Web. The structure of the domain in the question is a little vague so sorry if this is light on details, but the principle is the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With