Ejemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>Raises the <see cref="E:System.Windows.Application.Startup" /> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            try
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule <AppRegistry>();

                IContainer container = builder.Build();
                RxAppAutofacExtension.UseAutofacDependencyResolver(container);

                var factory = container.Resolve <IWindowFactory>();
                var window  = factory.Create(true);
                //window.Dispatcher => //System.Windows.Application.Current.Dispatcher

                // Run start up jobs
                // var tradePriceUpdater = container.Resolve<TradePriceUpdateJob>(); // Set to AutoActivate() at registration.

                window.Show();
            }
            catch (System.Exception ex)
            {
            }
        }
Ejemplo n.º 2
0
        public void Should_resolve_screen()
        {
            var builder = new ContainerBuilder();

            builder.RegisterScreen(Assembly.GetExecutingAssembly());
            RxAppAutofacExtension.UseAutofacDependencyResolver(builder.Build());

            var screen = Locator.CurrentMutable.GetService <IScreen>();

            screen.ShouldNotBeNull();
            screen.ShouldBeOfType <Screen>();
        }
Ejemplo n.º 3
0
        public void Should_resolve_view_models()
        {
            var builder = new ContainerBuilder();

            builder.RegisterViewModels(Assembly.GetExecutingAssembly());
            RxAppAutofacExtension.UseAutofacDependencyResolver(builder.Build());

            var vmA = Locator.CurrentMutable.GetService <ViewModelA>();

            vmA.ShouldNotBeNull();

            var vmB = Locator.CurrentMutable.GetService <ViewModelB>();

            vmB.ShouldNotBeNull();
        }
Ejemplo n.º 4
0
        public void Should_resolve_views()
        {
            var builder = new ContainerBuilder();

            builder.RegisterViews(Assembly.GetExecutingAssembly());
            var container = builder.Build();

            RxAppAutofacExtension.UseAutofacDependencyResolver(container);

            var viewA = Locator.CurrentMutable.GetService(typeof(IViewFor <ViewModelA>));

            viewA.ShouldNotBeNull();
            viewA.ShouldBeOfType <ViewA>();

            var viewB = Locator.CurrentMutable.GetService(typeof(IViewFor <ViewModelB>));

            viewB.ShouldNotBeNull();
            viewB.ShouldBeOfType <ViewB>();
        }
Ejemplo n.º 5
0
        public App()
        {
            var assembly = Assembly.GetExecutingAssembly();
            var builder  = new ContainerBuilder();

            // Since we're using the ReactiveUI.Autofac library this is all we need to do
            //  to wire up our views and view models. Since it's based on Autofac we can
            //  also freely inject any dependencies we've registered.
            //
            builder.RegisterForReactiveUI(assembly);
            RxAppAutofacExtension.UseAutofacDependencyResolver(builder.Build());

            // We've replaced Splat's default locator with the Autofac version so
            //  we can continue to use the code shown in the ReactiveUI examples
            //
            var view = (Views.MainWindow)Locator.CurrentMutable.GetService(typeof(IViewFor <MainWindowViewModel>));

            view.Show();
        }
Ejemplo n.º 6
0
        public IContainer Boot()
        {
            try
            {
                var builder = new ContainerBuilder();

                var assembly = Assembly.GetExecutingAssembly();

                builder.RegisterAssemblyTypes(assembly)
                .Where(t => typeof(IAutoMapperConfiguration).IsAssignableFrom(t))
                .InstancePerLifetimeScope().AsImplementedInterfaces()
                .AsImplementedInterfaces();


                var container = builder.Build();

                var automappers = container.Resolve <IEnumerable <IAutoMapperConfiguration> >();

                var config = new MapperConfiguration(cfg =>
                {
                    foreach (var instance in automappers)
                    {
                        var automapperConfig = instance;
                        automapperConfig?.ConfigureAutomapper(cfg);
                    }
                });

                var mapper = config.CreateMapper();

                RegisterCommonServices(mapper);

                // register the native types
                _platformInitializer.RegisterTypes(_containerBuilder);

                // register the views and view models
                _containerBuilder.RegisterViews(assembly);
                _containerBuilder.RegisterViewModels(assembly);
                _containerBuilder.RegisterScreen(assembly);

                _containerBuilder.RegisterType <LoginView>().As <IViewFor <LoginViewModel> >();

                var container1 = _containerBuilder.Build();
                RxAppAutofacExtension.UseAutofacDependencyResolver(container1);

                StartAppCenter();

                Router = new RoutingState();

                // You must register This as IScreen to represent your app's main screen
                Locator.CurrentMutable.RegisterConstant(this, typeof(IScreen));

                NavigationService.Create(container1, Router);
                NavigationService.Navigation(typeof(LoginViewModel));

                return(container1);
            }
            catch (Exception ex)
            {
                // log
                throw ex;
            }
        }