Is there an issue with having more than one IoC Container in a solution?

Not really in the case of Funq (which is used in ServiceStack) as its a statically bound IOC which is more like a C# Dictionary full of cached constructor delegates than an full-featured IOC. It is included in source form in ServiceStack and was chosen because it is very fast (i.e. Near native speeds): codeproject.com/Articles/43296/Introduct... The registration in Funq is non-invasive i.e.

You have to manually register your dependencies as it doesn't indiscriminately scan all your assemblies registering all dependencies it finds. If you choose not to use Funq and use another IOC by injecting an IContainerAdapter and delegating to another IOC, then your Funq dictionaries of cached delegates will be empty (i.e. Cache miss) and ServiceStack will simply ask your preferred IOC for the dependency instead The only thing to keep in mind is, the Web Services themselves are registered and auto-wired by ServiceStack and not your preferred IOC container, so in this case your IOC acts more like a repository of dependencies.

Not really in the case of Funq (which is used in ServiceStack) as its a statically bound IOC which is more like a C# Dictionary full of cached constructor delegates than an full-featured IOC. It is included in source form in ServiceStack and was chosen because it is very fast (i.e. Near native speeds): codeproject.com/Articles/43296/Introduct... The registration in Funq is non-invasive i.e.

You have to manually register your dependencies as it doesn't indiscriminately scan all your assemblies registering all dependencies it finds. If you choose not to use Funq and use another IOC by injecting an IContainerAdapter and delegating to another IOC, then your Funq dictionaries of cached delegates will be empty (i.e. Cache miss) and ServiceStack will simply ask your preferred IOC for the dependency instead.

The only thing to keep in mind is, the Web Services themselves are registered and auto-wired by ServiceStack and not your preferred IOC container, so in this case your IOC acts more like a repository of dependencies.

Thanks for the response! I had successfully wired up an adapter for Ninject, however, I was getting errors that there were no bindings for "RequestContext"...after specifying this binding my services would work on the first call but could not be found on subsequent calls..any input on this? – stephen776 Oct 11 at 14:27 ahh yeah, just return null (follow the end of the thread).

Also you should make AppHost internal, for an explanation see: groups.google. Com/forum/#! Searchin/servicestack/… – mythz Oct 11 at 15:26.

I would say - it depends. If the IoC frameworks you're using have different dependencies with no overlap then I don't see any issues. If as I suspect though, you're effectively having to double-up your IoC registrations then I guess it depends on how you're managing the lifetime of your dependencies.

If all your dependencies are transient or created through custom factory methods then you'll probably be OK. However things may well get unpredictable once you start trying to throw singletons or 'instance per web request' dependencies into the mix. I've never used Funq before, but if it's a capable IoC container I'd recommend removing Ninject from your project if possible.

Aside from eliminating the prospect of your application having hard to track bugs, it will keep your code much more DRY and consistent.

I don't know whether it'll break in the future, but it might. To minimise the risk, you could try unit-testing your injection routines, so then when you introduce the changes you'll have a mechanism to ensure that your injection routines still work. Generally, I think that consistency improves quality, so I would consider refactoring code to use a single provider.

I use Ninject and I have 4 modules for injecting services and repositories. Each module contains 10-20 injection routines - I can refactor these within an hour. If your project is of similar size, then refactor and use a single IoC.

Edit I have never used ServiceStack. Net, but how dependent is your project on this framework/toolkit? Are you likely to replace it with something else in near future?

How dependent is it on your MVC project? I'm trying to think of a scenario where maintenance cost of using one IoC will be higher than maintenance cost of using another IoC. Looking at Ninject, there is Ninject and Ninject MVC 3 extension.

The extension simplifies the job and doesn't conflict with anything else. In my case, I had to replace standard Ninject with Ninject MVC 3 because for me it did everything the standard version did (+ extra) and was easier to configure.

I totally agree. Funq has the ability to plug in adapters to use your own container to solve the dependecnies. I have this working using Ninject, but I am running into problems resolving the internal dependencies within the servicestack library.

The only way I have successfully got this working is by leveraging both IoC containers- Ninject for MVC and Funq for SS – stephen776 Oct 11 at 12:20 Please see the edit – CodeRush Oct 11 at 12:33.

Until 4.1, it had UnityContainer and not IoCContainer. Edit: What is that unity object you are passing? You may have to post some code.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions