I'm working on an ASP.NET MVC solution that has two projects, WebUI and DAL. WebUI references DAL. DAL has the repository and context, while WebUI contains Authentication and Authorization classes.

The problem is that I have to send some of the Claim's information to the Entity Framework's context constructer.

I have several options:

  1. Changing repository's constructor and send the parameter there. This way I have to change around 200 references.

  2. Reference the WebUI project and change the repository to extract required information. This is not possible, since WebUI references DAL and I cannot add circular reference.

  3. Building another project and move the authentication and authorization entirely to that project and reference it in the two other projects. This should be the best option, but is a little painful, specially that authentication and required method depends on the HttpContext of the current controller.

Any guidance and suggestion is welcome, please let me know if you need any more description.

  • 1
    Have you considered putting an interface in your DAL that your UI layer can then implement to provide the necessary information, I.e. applying the Dependency Inversion Principle to the problem? – Jules Aug 1 '15 at 9:56
  • Thanks for your comment Jules, I added an Interface to the DAL project and implement it in the UI. But the problem is Dependency Inversion, I tried to use Ninject. I bind the interface and implementation, and I still get error about zero arguments. Can I use the resolver for the instances that I'm creating manually, i.e. the repository instances? What did I get wrong? – Akbari Aug 2 '15 at 3:30
  • 1
    That depends on too many details to be sure, but possibly. You would have to rename the class in your ui and introduce a new interface in your DAL with the original name, and then let the UI class implement the DAL interface. This may or may not require substantial changes, but even if it does those are changes your IDE ought to be able to perform automatically. – Jules Aug 2 '15 at 12:16
  • I was trying to add an interface and class just for the claims and use it in the repository. With your second comment I think you're talking about the repository itself? I copied the repository to the UI project, where I have access to the required information, but I didn't change the namespace so I don't have to change anything. It seems like a dirty hack, nevertheless it works. I'd be grateful if you could explain in more details about... . :) – Akbari Aug 3 '15 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.