views:

41

answers:

1

I got a project named MyProject.Views and in this project I reference another project named MyProject.Models.

The MyProject.Models have a reference to Mysql.Data.dll. In the references option, the copy local is set to true.

My problem is I have to manually add a reference to MySql.Data.dll in the project MyProject.Views. Which I think is not a great idea. I would like to only add that dll in the project MyProject.Models because it is that project that needed that dll...

+2  A: 

This probably means that MyProject.Models is exposing something in its public interface that has a dependency on something inb MySql.Data.dll -- for example, a class that inherits from something in MySql.Data.dll, or a property of a type defined in MySql.Data.dll. The compiler error you get if you remove MyProject.Views' reference to MySql.Data.dll should help you track down what that dependency is: I think it tells you what the depended-on thing in MySql.Data is, but that should hopefully give you an idea of what in the Models project might depend on that thing.

itowlson
Ok, I think I got your idea. But, I'll give you another example. I got domain class that inherit from ActiveRecordBase (from Castle project). And I need to use those classes in my View. How can I deal with that ? I mean I want those classes to inherit from ActiveRecordBase but I don't want to add a reference in my view project to Castle.ActiveRecord.dll
Melursus
Unfortunately you are out of luck. If your view project has to refer to class derived from ActiveRecordBase, your view project needs to have a reference to ActiveRecordBase. The only way around this is to not refer to the derived class directly, e.g. refer to it through an interface instead (and e.g. use a factory method within your Models project to create instances of the class but return them as instances of the interface).
itowlson
What I don't get is that if MySql.Data.dll is outputed in my model project bin. There's no way to automatically referenced it in my view project when I reference my model project ?
Melursus
It's automatically copied because Visual Studio chases dependencies when copying referenced DLLs to the output directory. File copying is about what the Models DLL needs in order to run. Referencing is about what the Views DLL needs in order to compile.
itowlson