0

I'm probably not phrasing this question properly, but hopefully I can get the intention across.

I have an application with three projects. Project 1 is the web-facing part of the application. Project 2 is an API for accessing information. Project 3 is the part which accesses the database to obtain information, and returns that information to the caller.

From Project 1, I call methods contained within objects in Project 3, in order to access / modify information for use on the website. So, for example, from Project 1, I'll call Project3.classes.myObject.getObject(2) to get an instance of myObject based on a database query for objectID 2.

myObject has a whole bunch of attributes which I make use of in Project 1. These attributes are not all necessarily visible on the website, many are used internally within Project 1.

Now, from Project 2, I want to be able to return this information through an API call. So for example, calling the API with /controllers/myObject/2 would also invoke the Project3.classes.myObject.getObject(2). But when I'm calling from Project 2, I would like to restrict the attributes that are returned.

I know I can accomplish this by wrapping the returned object in Project 2, and limiting what is actually returned from the API call in that manner. But, is there any way I can have this be done within Project 3 instead?

I know that when I declare an attribute as "public", it is available to any assembly that calls it, and I know if I make it "internal", it is only available to the containing assembly. Is there any modifier which I can use that says, instead of "any" assembly that calls it, only specific assemblies?

Or am I thinking about this completely the wrong way?

1 Answer 1

0

seems like ur talking about adding attribute

[assembly:InternalsVisibleTo(Project1)]

to Project3 AssemblyInfo.cs

Next set all the props which should be visible to Project1 but not to Project2 as internal.

Having said that, I really don't think it's a good design, although I have seen that used in real world API. The intention was to share some functionality between DLLs of the API while hiding it from 3rd party apps.

https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(v=vs.110).aspx

2
  • That sounds like it is exactly what I'm looking for. Can you clarify a bit though, on why you think it's not good design? Commented Dec 21, 2017 at 22:34
  • I think it just makes the code very unclear and hard to maintain. Internal was designed for keeping stuff internal and i think this attribute was originally intended for unit testing of internal classes. Its much clearer just to create 2 interfaces for different uses and factory for each and keep the whole implementation internal. Commented Dec 22, 2017 at 9:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.