Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I avoid 'chained' references in Visual Studio with class libraries?

I have something like the following setup in a Visual Studio C# .NET solution:

Project 1 - TrainDisplay - a WinForms application to display train arrivals.

Project 2 - TrainFetcher - is a re-usable class library to fetch data about trains.

Project 3 - TrainsDataModel is a data model, containing classes common to all other projects, e.g. Train.cs, TrainRoute.cs and so on.

Each has the following references:

Project 1 : References 2 and 3

Project 2 : References 3

Is it bad to use references in this way; i.e. does project 1 end up with two references to project 3; one direct, and one via project 2?

like image 243
Carlos P Avatar asked Jun 24 '12 17:06

Carlos P


People also ask

How do I reference another project in Visual Studio?

Restart Visual Studio, create a new C# UWP app project, and then right-click on the project and choose Add Reference.


1 Answers

It's not wrong per se, the compiler will do The Right Thing®.

But it could be an indication of a not-so-great design.

Try to design the three layers in such a way that 2 only depends on 3, and that 1 only depends on 2.

Edit: the last sentence wasn't clear. What I meant was: "design the three layers so that your business objects only need to reference the data access code, and that the UI only deals with business objects".

Ultimately, the right way to do it really depends on your architecture (use of ORM vs issuing queries manually, Active Record vs Mapper and the like).

like image 82
s.m. Avatar answered Sep 28 '22 21:09

s.m.