Search code examples
c#code-organizationcircular-dependency

circular dependency


I have 2 projects

  • UI: contains all my forms and user control
  • Translation: contains my translation code used to translate the UI

The Ui project obviously needs a reference to the translation project since it needs translation.

Since I defined custom user controls in the UI that need special translation. The Translation project needs to know the type and thus translation also needs a reference to UI resulting in a circular dependency.

is this actually a problem and yes how do I solve this best? Do I take out the custom types and put them in a seperate project?

Thanks


Solution

  • Following good practice, and especially sepatation of concerns, your translation library should know nothing about what it is translating, only that it needs to translate text a into b.

    Typically this is done with a methods or methods which take an identifier for a string, and a culture to translate to.

    CultureInfo ci = new CultureInfo("en-US");
    var tranlated = MyTranslator.Translate("HelloWorldMessage",ci);