How to enable chicken dependency resolution for MVC using Authorize attribute?

I have a situation where the fact that the user is not logged in does not allow me to create my dependencies between controllers.

[Authorize]
class MyController : Controller
{
    public MyController(MyService service)
    {
    }
}

class MyService
{
    public MyService()
    {
        // requires information which only
        // becomes known after the user logs in
    }
}

My question is: can I do something so that the MVC environment first looks at the Authorize attribute and then resolves the controller instance?

The above would be much more preferable for me than one of the following:

  • Modifying the MyService service to work with creation before the user logs in
  • Func Injection
  • Go to service location

MVC, : " , , - ..."

+4
2

, , , .

.

// ,

, . , . .

, , . , ( , ). , , . , ; ( ).

+4

, , MVC Request.

, , , , , . OnAuthorization, , OnAuthorization.

, , , , . , , , , .

.

https://www.simple-talk.com/dotnet/.net-framework/an-introduction-to-asp.net-mvc-extensibility/

+1

Source: https://habr.com/ru/post/1525486/


All Articles