Question

I've created a component in .NET which is intented to be used in multiple .NET solutions in other companies or development teams.

My component consists of multiple DLLs. Roughly, it has:

  • A core DLL that can make lots of operations, and
  • A facade DLL that offers just a small subset of those operations, so that component can be customized for different customers or integrations.

The thing is that I don't want anybody to be able to access the core methods, but only the facade ones. This way I would ensure that nobody tries to cheat by calling core methods directly, instead of the facade methods.

Is it possible to achieve that? Is there any pattern or good practice in order to achieve such encapsulation?

Was it helpful?

Solution

Make the access modifiers of the core types internal and utilise the InternalsVisibleToAttribute to share internal implementations across your own assemblies. This attribute would allow your facade DLL to get access to core internals.

This won't stop the determined person from using reflection, however. What it does it make it non-trivial to get access, which is usually enough to direct most people across to the publicly exposed types.

Also, a lack of documentation on the internal stuff when publishing the assemblies will dissuade people - coupled with very good documentation for the public types.

It would be prudent to always look at how people are trying to use your assemblies. There may be types in core that people favour heavily because they are useful or have a use you had not considered - be prepared to expose these through the facade to meet consumer demand.

OTHER TIPS

You can change all your core public methods/members/etc to internal and then use InternalsVisibleToAttribute to make all the internal items visible to the façade.

An alternative would be to use the StrongNameIdentityPermissionAttribute which will:

Quarantee that a caller (either the immediate caller or one somewhere up the call chain) has been signed with a particular strong name. (This no longer works as intended)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top