Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a doubt. I have a singleton object of an interface defined in the Autofac container. I use this object across my solution. I need to access the interface inside custom authorize attribute and I need to resolve the dependency.

What I have tried:

I have tried sending it through constructor parameter but it says object reference needed. I also have tried using Dependency resolver but that also doesn't work either  
Posted
Comments
F-ES Sitecore 20-Sep-18 4:32am    
You should use DependencyResolver to access your container, constructor injection is only for controllers, not every class. If DependencyResolver doesn't work then chances are it is something to do with either how you are registering your container, or registering the services. We can't tell you which as we can't see your code and "doesn't work" does not convey enough information to allow someone to diagnose a problem.
sai sruthi 21-Sep-18 5:48am    
thanks for the help, as u said the dependency resolver helped,
actionContext.Request.GetDependencyScope().GetService(typeof(UserService)) as UserService

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900