GetAllInstances simple injector throws an exception with Caliburn Micro

I worked on Simple Injector and Caliburn micro , but almost 2 years have passed. Now today, when I tried to create a simple WPF application. First I finish reading the documentation, as both libraries have made a lot of changes.

I ran into several problems, such as the "view cannot be found", which will later resolve, but now I'm stuck in a strange problem. I tried to turn on the recorder and that’s all, but I don’t know if there is a Caliburn microchip problem or a simple injector.

Here is my bootstrap class:

 internal class AppBootstrapper : BootstrapperBase
    {
        public static readonly Container ContainerInstance = new Container();

        public AppBootstrapper()
        {
            LogManager.GetLog = type => new DebugLogger(type);
            Initialize();
        }

        protected override void Configure()
        {
            ContainerInstance.Register<IWindowManager, WindowManager>();
            ContainerInstance.RegisterSingleton<IEventAggregator, EventAggregator>();

            ContainerInstance.Register<MainWindowViewModel, MainWindowViewModel>();

            ContainerInstance.Verify();
        }

        protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
        {
            DisplayRootViewFor<MainWindowViewModel>();
        }

        protected override IEnumerable<object> GetAllInstances(Type service)
        {
            // This line throwing is exception when running the application
            // Error: 
            // ---> An exception of type 'SimpleInjector.ActivationException' occurred in SimpleInjector.dll
            // ---> Additional information: No registration for type IEnumerable<MainWindowView> could be found. 
            // ---> No registration for type IEnumerable<MainWindowView> could be found. 
            return ContainerInstance.GetAllInstances(service);
        }

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

        protected override IEnumerable<Assembly> SelectAssemblies()
        {
            return new[] {
                    Assembly.GetExecutingAssembly()
                };
        }

        protected override void BuildUp(object instance)
        {
            var registration = ContainerInstance.GetRegistration(instance.GetType(), true);
            registration.Registration.InitializeInstance(instance);
        }
    }

Not sure what I'm missing here?

+4
1

v3 . , , - № 98. Simple Injector v3 . , Caliburn.

, GetAllInstances :

protected override IEnumerable<object> GetAllInstances(Type service)
{
    IServiceProvider provider = ContainerInstance;
    Type collectionType = typeof(IEnumerable<>).MakeGenericType(service);
    var services = (IEnumerable<object>)provider.GetService(collectionType);
    return services ?? Enumerable.Empty<object>();
}
+8

All Articles