I would like to pass certain data from an instance of an object to its attribute, and I have troubles inderstanding how to implement it. Here’s a sample:
[AuthenticateAttribute]
public class MyController: Controller
{
UserInfo info;
}
The idea is that AuthenticateAttribute instance would populate the UserInfo instance.
I want to pass reference to info to an instance of AuthenticateAttribute and thereby eliminate strong coupling between the attribute and the particular MyController class.
Is this possible?
The attribute itself shouldn’t have the
UserInfofield IMO. Bear in mind that there will be one instance of the attribute for the type it’s applied to – not one per instance of that type.If you could give a fuller example (showing the code it’s applied to) we may be able to help more…