1
votes

I've been following This MSDN tutorial about implementing OWIN to manage a single instance of DbContext and Identity UserManager classes.

It seems nice, but I'm also learning about Dependency Injection (I've been using Ninject) to get instances of objects.

I understand that OWIN creates and retrieves a single instance of an object per request and DI will return a new instance for every time that we require an object.

Do the two work together or share common features?

Should I be choosing one or the other or both together?

For example, should I be setting up an interface that has methods to return instances of my objects from the OWIN context and then injecting that into my controller?

1

1 Answers

3
votes

The CreatePerOwinContext/Context.Get approach is not a general replacement for a regular IoC container and does not contain the [expected] features associated with dependency management - trivially, it provides no method for injecting dependencies. If anything, it is more akin to a basic Service Locator or [ab]use of the HttpContext.

Thus, while it can be used to establish an IoC container, it does not replace DI or an IoC container.