Overriding ServiceLocator

May 7, 2011 at 7:43 AM

Hello, you are using ninject container

var serviceLocator = new NinjectServiceLocator(kernel);
ServiceLocator.SetLocatorProvider(() => serviceLocator);

That's overriding my unity container so i get very funny errors because until instantiation of game class i have one container and after - another - ninject.

Could you be so kind to post here a short guide how to deal if i'm using another IoC container in my app?

May 7, 2011 at 6:31 PM

I've been wanting to get the Ninject dependency out of Balder, and have in fact implemented a way in a parallel project I have running called Bifrost. The biggest problem is that I want Balder to be very easy to use and not need to know about the IoC or anything. 

The way I see it for short terms is to not use the Common ServiceLocator internally and wrap it up in my own thing - this should be fairly easy to do and non intrusive to the way Balder works. On the long term I'm thinking about getting Ninject out of there, as I'm not sure its adding much value at this point.

May 9, 2011 at 11:39 AM
Edited May 9, 2011 at 11:51 AM

I've eliminated usage of ServiceLocator by introducing simple class 

    public static class DependencyResolver
        public static NinjectServiceLocator ServiceLocator { get; set; }

        public static T GetInstance<T>()
            return ServiceLocator.GetInstance<T>();

ans swaping all calls ServiceLocator.Current.GetInstance to DependencyResolver.GetInstance. That's working pretty good now but i'm looking forward to you solution as i'm not going to merge code every time you will push an update.