Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guice equivalent in C# [closed]

I am a Java developer and I use Guice heavily. Now I'd like to learn C# but to my surprise I have not found an equivalent to Guice. I have just found tools like Ninject, Unity, StructureMap but I am looking more for a tool like Guice. I do not want to write down all my registrations manually... so what are the best options?

like image 734
Alex Valerio Avatar asked Jun 01 '12 05:06

Alex Valerio


3 Answers

The one I like the most is Ninject. It has a plug-in to auto-register components based on conventions.

I am actually writing an open source library to auto-register components; it is designed to support most of the current IoC containers we have in .NET. This is the link in case you are interested: https://github.com/jupaol/NAutoRegister (check the Developer Branch).

With AutoFac you can register components easily as well.

I have checked out Guice and it's simply awesome. A good initiative would be to port Guice to .Net, just like many other Java tools.

like image 73
Jupaol Avatar answered Nov 20 '22 12:11

Jupaol


I haven't used Guice, so if your talking about automatic registration of components, many IOC containers provide some sort of assembly scanning.

Have a look at the documentation for AutoFac, you can see its quite easy to register compontents.

var dataAccess = Assembly.GetExecutingAssembly();

builder.RegisterAssemblyTypes(dataAccess)
    .Where(t => t.Name.EndsWith("Repository"))
    .AsImplementedInterfaces();
like image 23
Rohan West Avatar answered Nov 20 '22 14:11

Rohan West


I've made a Guice port for C# with some of my favorite features. Fairly small code base, but has been used on over 50M devices via Unity3D, and probably more as I've just found out Disney is using it at the moment as well.

https://github.com/disturbing/suice

like image 2
Joseph Cooper Avatar answered Nov 20 '22 13:11

Joseph Cooper