Question

Having 3 projects inside a solution forming a structure like:

GUI <- Implementation <- DataAcess

I have a class inside GUI visualBic that gets its properties filled after user interacts.

The problem I have is to pass those properties to DataAcess project. What I can do is to use dataccess inside implementation as Implementation is one level up... but can not use GUI in implementation as Implementation is one level down...

When tried filling database in Implementation, as I do not have GUI visualBic class inside Implementation project, I was not able to do so... I can not create an instance, or add a reference of GUI in Implementation project, because that would create a circular dependency

The question is how can I use a class in GUI project inside Implementation project not causing circular dependency ?

I could move GUI visualBic class to Implementation project, but GUI visualBic class uses some stuff that is only GUI (dlls), and that stuff can not live in Implementation project

Was it helpful?

Solution

Clearly the visualBic class is not the class to be passing to the implementation! As you noted, it has UI specific fields/logic and so is not suitable for living in the "Implementation" project where it would have to for classes in that project to know about it.

The answer to your question is you don't EVER want a reference from "Implementation" to the GUI because that tightly couples the two, completely defeating the purpose of separating them in the first place (even if it was technically possible).

Instead, you need a new object that CAN live in "Implementation" that your GUI fills out and passes to the appropriate function.

My visualBic: (in GUI assembly)

public class visualBic
{
   public String Name {get; set;}
   ... Bunch of other, potentially GUI stuff
}

BicDTO: (In Implementation assembly)

public class BicDTO
{
    public String Name {get; set;}
}

Translation function: (In GUI assembly)

public void SendImplementationData(visualBic data)
{
   BicDTO implementationObject = new BicDTO();
   implementationObject.Name = data.Name;
   implementationRef.SendData(implementationObject);
}

Obviously this is highly generalized, but it should get the point across. Let me know if I can clarify anything else!

OTHER TIPS

The answer is that you can't. If you need to use a type in Implementation then it must either be defined in Implementation or else defined in a separate project that both Implementation and GUI reference. You would then map the data from your visualBic class to this other class and pass that down to Implementation.

I recommend using Data Transfer Objects for passing data, properties, etc between your layers/projects. Create a separate DTO project and keep your DTOs there. The you can ref them across all other projects.

You can create the DTO in your UI layer, fill it, then pass it to your Implementation layer to apply rules/change values then pass it again to your data access layer for persistence, etc.

Another DTO link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top