0

I have a Web API 2.2 application and want to filter data based on the current user that is accessing the Web API. The User property on the ApiController has the information that I need. But how can I get that information to my service class? Of course I don't want to pass everything around via parameters, but via my DI.

csv
  • 23
  • 6

1 Answers1

0

You want to pass your principal into the methods of the service class, not as a constructor parameter. Depending on how you are using DI, that service class can hang around for a while, and you don't want the class to have the principal in that case. You want your principal to be short lived.

MichaelDotKnox
  • 1,312
  • 1
  • 14
  • 17
  • Good point. Somebody in the future might decide to change DI behaviour or a bug might come along. Better to have it short lived. – csv Jul 06 '17 at 08:35