Spring and dependency injection

Jul 20, 2012 at 5:55 PM
Edited Jul 20, 2012 at 6:01 PM

Hello,

I'm trying to develop a WPF application with Caliburn, Spring.NET NHibernate. I have it separated in several assemblies, depending on the business area (it means that I can have a folder Views and ViewModels in more than one). My bootstrapper is very simple, and as you can see, I select the assemblies that have viewmodels and views:

 

public class SpringBootsrapper : Bootstrapper<MainViewModel> 
    {
        protected override IServiceLocator CreateContainer()
        {
            XmlConfigurator.Configure();

            var cxt = ContextRegistry.GetContext();
            
            GenericApplicationContext context = new GenericApplicationContext(cxt);
            
            var container = new SpringAdapter(context);

            return container;
        }

        protected override IEnumerable<Assembly> SelectAssemblies()
        {
            IEnumerable<Assembly> assemblies = base.SelectAssemblies();
            IList<Assembly> ass = new List<Assembly>(assemblies);
            ass.Add(Assembly.GetAssembly(typeof(LoginViewModel)));
            return ass;
        }
}

My MainViewModel is like:

[Singleton(typeof(MainViewModel))]
    public class MainViewModel : Screen
    {
        private readonly IWindowManager windowManager;

        [ImportingConstructor]
        public MainViewModel(IWindowManager windowManager, IServiceLocator locator)
        {
            this.windowManager = windowManager;
            string[] pepe = ((SpringAdapter)locator).Context.GetObjectDefinitionNames();
            IEnumerable < LoginViewModel> logins = ((SpringAdapter)locator).GetAllInstances<LoginViewModel>();
            LoginViewModel loginWindow = IoC.Get<LoginViewModel>();
            if (loginWindow == null)
            {
                MessageBox.Show("Not exists");
            }
            else
            {
                windowManager.ShowDialog(loginWindow);
            }
        }
    }

When I start the application it comes to this constructor, but IoC is never finding LoginViewModel, but here the IWindowManager is injected.

What I am doing wrong?

The code for LoginViewModel is in another assembly:

[Export(typeof(LoginViewModel))]
public class LoginViewModel : Screen
{
    [Import]
    private IUsersService service;

    .....

}

Thanx!