This project is read-only.

Mono support? (Update: Works fine in Mono 3.0)

Dec 5, 2012 at 12:37 AM
Edited Dec 5, 2012 at 12:38 AM

Hi,

Does Simple Injection support Mono? I'd like to try it instead of Ninject (which supports Mono). I will try it out myself, but I'm just curious as to if you "officially" support it.

Thanks!

Dec 5, 2012 at 7:19 AM

Just tested it in Mono 3.0.1 on Ubuntu Linux and Mono 3.0 on Debian Linux - It works! I tested in a console application, as well as in an MVC 4 app (brand new based on the "Empty" template in Visual Studio). RegisterPerWebRequest is also working as expected.

Great work! I love Simple Injector so far, nice and simple. :)

Dec 10, 2012 at 11:56 PM

Hi Dan,

Note that Mono is not officially supported.

Though, since most of the framework depends on .NET 3.5 core libraries, chances are high that everything works as expected on Mono. But please be aware of the following:

  • Unit tests are never ran on Mono. Simple Injector might therefore depend on .NET features that are buggy in Mono.
  • Mono uses a memory model that is less strict than the .NET 2.0 memory model, and there could be thread-safety issues in using Simple Injector because of that.

By running the Simple Injector unit tests on Mono, you can check whether everything works as expected for the release you are using, if you haven’t already.

I think it is not very likely that you encounter a race condition, but you can prevent any issues by making sure all expression trees are compiled for all root types before any multi-threaded actions take place on the container. This basically means that you should either call container.Verify() directly after configuring the container, or loop manually over all explicitly resolved types (such as controller’s and such) and request them once from the container. This ensures that everything is built-up and makes sure the container doesn't need to take any locks at any later moment. This might increase the start-up time of the application, but it does prevent any possible concurrency issues in Mono.

Dec 11, 2012 at 12:47 AM

Thank for your reply. I wasn't sure whether the unit tests could run on Mono or not since they're using the Visual Studio test framework. I'll try it out when I get home tonight (if I remember :P) and I'll see how they go.

I am already calling container.Verify() directly after configuring the container.

Dec 11, 2012 at 8:17 PM
Edited Dec 11, 2012 at 8:19 PM

One thing you might want to check is whether instances that are registered as Per Web Request are disposed when running in Mono. The SimpleInjector.Integration.Web.dll contains a [PreApplicationStartMethodAttribute] which let's ASP.NET trigger the registration of an HTTP Module that ensures Per Web Request registered instances are disposed when the HTTP request ends. It is possible that this event is not fired under Mono.

Feb 14, 2013 at 12:20 PM
For Simple Injector 2.0. changeset 98432 fixes possible thread-safety issues for other architectures than x86 and x64 and for runtimes that simply follow the ECMA C# specs. This means that Simple Injector v2 can -from a thread-safety perspective- safely run on Mono and ARM processors.
Feb 25, 2013 at 2:48 PM
Simple Injector 2 has just been released.
Marked as answer by dot_NET_Junkie on 11/5/2013 at 7:36 AM