Since IAuthenticationManager implementation can be retrieved from OWIN context, but Castle Windsor's component registration must be done before resolving components, how can I register IAuthenticationManager as component to get injected anywhere?
AFAIK, I should use Component.For<IAuthenticationManager>().UsingFactoryMethod(...), but since I'm using OWIN/Katana, something like HttpContext.Current.GetOwinContext() won't work (and if it would work, I would hate to add a dependency to System.Web for this...).
What's the solution for this right now?
Temporal (or definitive) solution...
This is how I've managed to solve the issue.
First of all, I've implemented a simple OWIN middleware:
And I've configured
IAuthenticationManagerusingComponentRegistration<T>.UseFactoryMethodso I've implemented an extension method like this:Finally, I've registered
IAuthenticationManagerthis way:It smells...
BTW, I'm not self-convinced about the reliability of this solution since this should work unless you try to resolve components in another thread than the request one.
Sadly, it should be a lot of situations where this solution can fail. If your code implements non-blocking I/O, I expect to try to inject
IAuthenticationManagerfrom another thread from the one that set "owinContext" in theCallContext...I'll still look forward for other answers while I find a better and more elegant solution.