Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mookid8000/jug

Experimental DI container
https://github.com/mookid8000/jug

Last synced: 5 days ago
JSON representation

Experimental DI container

Awesome Lists containing this project

README

        

What?
====

Jug is an experimental DI container.

It is nowhere near finished. Actually it is probably not even the slightest bit functional.

Why?
====

After having messed a little bit with Castle Windsor's source code, I have been having some nasty thoughts on how container extensibility could be implemented. It may or may not work out.

What's interesting about it?
====

Not much, really. I was just a little bit inspired by one of the posts on Castle Windsor's UserVoice, that suggested that the container be put more to use in extensibility scenarios.

E.g. it is annoying with Windsor that `IHandlerSelector` is just a plan old object instance, that sits right there in the container - instantiated and all. Why not pull `IHandlerSelector`s from the container?

In Jug, you select between various implementations of the same service by implementing an `IComponentSelector<...>` like so:

var container = new Jug.Container();

// register services
container.Register()
.Register();

// register selector
container.Register>, MySelector>();

// selector will be asked for its opinion now:
var instance = container.Resolve();

and MySelector could look something like this:

public class MySelector : IComponentSelector
{
public ComponentModel Select(ComponentModel[] componentModels)
{
return componentModels.Single(c => c.ImplementationType.Name.StartsWith("Second"));
}
}

ensuring that `SecondImplementation` will be picked.

Now, imaging how nifty this could be when the selector depends on various business services and stuff, thus providing the hook that has always been missing in Windsor!

Disclaimer
====

As I said: "It is nowhere near finished. Actually it is probably not even the slightest bit functional."

Seriously!!