Limit a class library or assembly references to specific projects?

C

Che.Gonzalez

Can a project or assembly limit the projects that may reference it?
For example, I have a legacy project used by a data layer project. I
don't want the object model project to be able to directly access the
legacy project. The object model or business logic project should only
be allowed to reference the data layer project.

Thanks,
Ché
 
S

Stoitcho Goutsev \(100\)

Any assembly can use any public type of other assemblies. There is no way of
restricting this. If a type is public it can be used. However access to
internal types is limited only withing the assembly itself.
..NET 2.0 extends their visiblity by introducing *friend assemblies*, so the
internal types and members are visible inside the assembly and in all
assemblies that the declaring assembly define as *friends*. So there is
probably your solution. Declare all the types (or at least the ones that you
don't want to be shared with everybody) as internal and let the legacy
assembly declare the datalayer as *firend*. The downside of this that the
datalayer will see everything even types and members that are internal
implementation.

For declaring *friend assemblies* look at MSDN
http://msdn2.microsoft.com/en-us/library/0tke9fxk.aspx

Read carefully because there are some requirements to use that feature; they
even can make it inaplicable with your project. Keep in mind also that this
feature is not available in .NET 1.x


--
HTH
Stoitcho Goutsev (100)

Can a project or assembly limit the projects that may reference it?
For example, I have a legacy project used by a data layer project. I
don't want the object model project to be able to directly access the
legacy project. The object model or business logic project should only
be allowed to reference the data layer project.

Thanks,
Ché
 
C

Che.Gonzalez

Thank you very much... I appreciate your help. This should keep a
clear division and keep other developers from ruining the integrity of
a project by crossing bussiness logic with data layer code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top