How to encapsulate the child libraries classes being accessed c#?

Viewed 39

I have 3 projects. project 1 uses reference of project 2 and project 2 uses reference of project 3.Now this is what I want. as with above scenario project 1 can also use classes of project 3 which I not want to do so. so how I can encapsulate classes of project 3 to be used only in project 2 and not in project 1.

here is example class ABC is in project 3 which I am using in project 2 by referencing project 3 to project 2. and project 2 is referenced in project 1 and ABC class also become available in project 1 which it should not be.

all three projects are class libraries with .net core

1 Answers

There is a work-around that is to declare the classes as internal and use InternalsVisibleToAttribute on your project 3's assembly to allow all internal types to be usable in/visible to the project 2. Of course the internal classes will not be usable in the project 1 as well as any other projects.

Related