This project is inspired by Rob Eisenberg's excellent Caliburn Micro project.

As much as I love the framework - and it is astonishingly good - I wasn't mad on the SimpleContainer code that demonstrated IOC.

 

This code produces a single, small (~15k) dll that just drops into your WP7 project. Here's how to integrate into a Caliburn Micro for WP7 Bootstrapper:

 

public class TopBootstrapper : PhoneBootstrapper
    {
        private readonly IMicroIocContainer _container = new MicroIocContainer();
        
        protected override void Configure()
        {
            _container
                .Register<MainPageViewModel>("MainPageViewModel", true)
                .RegisterInstance<INavigationService>(new FrameAdapter(RootFrame))
                .RegisterInstance<IPhoneService>(new PhoneApplicationServiceAdapter(RootFrame));

        }

        protected override object GetInstance(Type service, string key)
        {
            return _container.Resolve(service, key);
        }

        protected override IEnumerable<object> GetAllInstances(Type service)
        {
            return _container.ResolveAll(service);
        }

        protected override void BuildUp(object instance)
        {
            _container.BuildUp(instance);
        }

 

Of course, you are not constrained to using Caliburn Micro to use this container - it works just nicely on its own.

Last edited Jun 27, 2011 at 10:21 PM by IanRandall, version 8

Comments

No comments yet.