I have 3 assemblies:
how can I make sure C does not use that interface?
splitting assemblies - not an option.
You could make the interface internal, and use InternalsVisibleToAttribute to allow B access to the internal members of A (by adding the attribute to A). It's very coarse-grained though - you can't do it for individual members; it's all or nothing.
In general though, this sort of specific limitation just isn't part of the design of access control within .NET or C#.
Of course you could try splitting out the interface into a new assembly, and make that available to both A and B via InternalsVisibleTo - but you wouldn't want to do this too often. The platform isn't designed for this sort of thing. (It'll work, but it'll get harder to work with the more types you do this to.)
I'd place the interface in its own assembly (.csproj) and make only project B reference that assembly.
This way way you achieve, in my opinion, the best encapsulation while adhering to best practices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With