lordvlad30
lordvlad30

Reputation: 451

avoiding circular dependency in MVC.NET

I have a bit off a problem with my project references as shown below First you have the standard layer model and a MVC.NET project on top but then the red lines begin to come in play:

Resources -> used for creating and editing resource files (.resx) and 
saving information about them to the database.

Utility -> has some custom attributes that go on top of the model objects. 

Resources needs Model because the Resource project saves a model object to the database. Model needs Utility because of the custom attributes.

Utility needs Resources because it has to get the correct errormessages in the correct language form the the Resources.ResourceManager

NOT PICTURED: MVC Web uses the Utility library too

Problem: Model, Utility and Resources form a circular dependency which is impossible, any suggestions on how to fix the structure so it does work?

Thanks for reading.

EDIT: example code from a Utility class, the ResourceManager comes from the Resource library:

public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
    ErrorMessage = ResourceManager.Get(HttpContext.Current.User.Identity.Lang(), ErrorMessageKey);


    ModelClientValidationRule CRequiredRule = new ModelClientValidationRule();
    CRequiredRule.ErrorMessage = ErrorMessage;
    CRequiredRule.ValidationType = "crequired";

    yield return CRequiredRule;
}

project structure

Upvotes: 0

Views: 81

Answers (0)

Related Questions