caliburn with structuremap (what am I doing wrong?)

Jan 10, 2011 at 12:33 AM
Edited Jan 10, 2011 at 12:35 AM

Hello,

I am trying get a CaliburnApplication (Ayende's Alexandria) run using structuremap as the IoC container. Here is the code for the App (which inherits from CaliburnApplication)

 

private StructureMap.IContainer container;
        protected override IServiceLocator CreateContainer()
        {
            container = new StructureMap.Container(x =>
            {
                x.AddRegistry(new ClientRegistry());
                x.Scan(scan =>
                {
                    scan.TheCallingAssembly();
                    scan.IncludeNamespaceContainingType<ApplicationModel>();
                    scan.AssemblyContainingType<MyBooksResponseConsumer>();
                    scan.ConnectImplementationsToTypesClosing(typeof(Consumes<>.All));
                    scan.WithDefaultConventions();
                });
                x.For<ApplicationModel>()
                    .Singleton();
            });

           container.AssertConfigurationIsValid();

            return new StructureMap.ServiceLocatorAdapter.StructureMapServiceLocator(container);
        }

        protected override void Register(IEnumerable<Caliburn.Core.IoC.IComponentRegistration> registrations)
        {   
            container.Configure(c =>
            {
                foreach (var item in registrations)
                {                    
                    c.For<Caliburn.Core.IoC.IComponentRegistration>().Use(item);
                }
            });
        }

        protected override object CreateRootModel()
        {
            return Container.GetInstance<ApplicationModel>();
        }

        protected override void BeforeConfiguration()
        {
            base.BeforeConfiguration();

            new EnvironmentVerifier().Verify();
        }
    }

 

When the project runs I get an exception : 

StructureMap Exception Code:  202No Default Instance defined for PluginFamily Caliburn.Core.IAssemblySource, Caliburn.Core, Version=2.0.0.39524, Culture=neutral, PublicKeyToken=8e5891231f2ed21f

I am not entirely sure if my implementation of the override void Register method makes sense. Previously I was getting

Cannot configure Caliburn. Override Register or provide an IServiceLocator that also implements IRegistry.

 

I am new to structuremap so I might not be setting it up right for use with caliburn. Please advice. Could someone explain the what typically goes in the Register override?

Thanks in advance.

Coordinator
Jan 10, 2011 at 12:44 AM

The implementation of register is incorrect. I recommend that you remove it and instead use Caliburn's StructureMap adapter.

Jan 10, 2011 at 12:22 PM

Rob,

Ayende's project has a reference to Caliburn.Core.dll with version 2.0.0.39524. I downloaded the release 1.1 to get the structuremap adapter and rightly so I do not see Caliburn.Core.Dll with that version.

If I go with the 1.1 dlls then it is unable to find a dependancy property within Caliburn.PresentationFramework.ViewModels.View.Context.

Any ideas?

Thanks for the pointer.

 

 

Coordinator
Jan 10, 2011 at 1:38 PM

His project was built against the trunk. The trunk was has also changed quite a bit since then. So, you will need to go with the trunk and then make some updates to the code.