Tigraine

Daniel Hoelbling-Inzko talks about programming

Dependency chain lookups with Pandora

Posted by Daniel Hölbling on May 28, 2009

Almost a week ago I introduced Pandora my own take on Inversion of Control. So I’m back to report some news.

New features:

  1. Multiple registrations of one service type
  2. Graph splitting
  3. Dependency chains of own service

Before only one service registration was possible, preventing you from doing all sorts of cool things.
For example it prevented you from registering a class like this one:

public class ClassWithDependencyOnItsOwnService : IService
{
    public ClassWithDependencyOnItsOwnService(IService service)
    {
    }
}

This class would typically be some sort of decorator that covers the IService interface with a thin layer of concerns (like logging/errorhandling/caching). Now, you can just register more than one IService and it will walk the graph for you:

[Fact]
public void CanResolveDependencyChainOfSameService()
{
    var store = new ComponentStore();
    store.Add<IService, ClassWithDependencyOnItsOwnService>();
    store.Add<IService, ClassWithNoDependencies>();

    var container = new PandoraContainer(store);

    var service = container.Resolve<IService>();

    Assert.IsType(typeof (ClassWithDependencyOnItsOwnService), service);     var ownService = (ClassWithDependencyOnItsOwnService)service;     Assert.IsType(typeof (ClassWithNoDependencies), ownService.SubService); }

Also now there is the possibility to split the graph at some point like this:

image

You don’t need three registrations for this, only one since every subresolving of IService will happen on it’s own. Something that isn’t really practical actually since we still lack the ability to influence the resolve process. Both IServices will be populated by the same registered type, it just won’t be the parent IService again.

I also spent almost the whole day refactoring the resolver code since I felt that it became quickly unreadable.

Next:

I still feel like the resolver needs some more refactoring, and I also want to improve the error messages. After that, I’d like to return my focus back to much needed features like lookup strategies and after that auto-configuration.

You can check out the code on the project site on bitbucket.

comments powered by Disqus

My Photography business

Projects

dynamic css for .NET

Archives

more