Пример #1
0
        private static IApplicationController InitializeApplicationController()
        {
            IIocContainer container = new LightInjectContainer();

            // Singleton registration is used for services
            // Low-level services
            container.Register <IWindowManager>();
            container.Register <IProcessMonitor>();

            // MediatR
            container.Register <IMediator, MediatR.Mediator>();
            container.RegisterInstance <ServiceFactory>(t => container.Resolve(t));
            container.Register(typeof(INotificationHandler <>), typeof(Program).Assembly);
            container.Register(typeof(IRequestHandler <>), typeof(Program).Assembly);
            container.Register(typeof(IRequestHandler <,>), typeof(Program).Assembly);

            // Configuration services
            container.Register <IConfigurationStorage>();
            container.Register <IAppConfig>();
            container.Register <IThumbnailConfiguration>();

            // Application services
            container.Register <IThumbnailManager>();
            container.Register <IThumbnailViewFactory>();
            container.Register <IThumbnailDescription>();

            IApplicationController controller = new ApplicationController(container);

            // UI classes
            controller.RegisterView <StaticThumbnailView, StaticThumbnailView>();
            controller.RegisterView <LiveThumbnailView, LiveThumbnailView>();

            controller.RegisterView <IMainFormView, MainForm>();
            controller.RegisterInstance(new ApplicationContext());

            return(controller);
        }
Пример #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO Switch to another container that provides signed assemblies
            IIocContainer container = new LightInjectContainer();

            // UI classes
            IApplicationController controller = new ApplicationController(container)
                                                .RegisterView <IMainView, MainForm>()
                                                .RegisterView <IThumbnailView, ThumbnailView>()
                                                .RegisterView <IThumbnailDescriptionView, ThumbnailDescriptionView>()
                                                .RegisterInstance(new ApplicationContext());

            // Application services
            controller.RegisterService <IThumbnailManager, ThumbnailManager>()
            .RegisterService <IThumbnailViewFactory, ThumbnailViewFactory>()
            .RegisterService <IThumbnailDescriptionViewFactory, ThumbnailDescriptionViewFactory>()
            .RegisterService <IConfigurationStorage, ConfigurationStorage>()
            .RegisterInstance <IApplicationConfiguration>(new ApplicationConfiguration());

            controller.Run <MainPresenter>();
        }