public ViewModelLocator()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<MainViewModel>();
            builder.RegisterType<ASSCount>().Named<ISubtitleCount>(".ASS");
            builder.RegisterType<SRTCount>().Named<ISubtitleCount>(".SRT");

            var container = builder.Build();

            var locator = new AutofacServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => locator);
        }
Example #2
0
        public static void Run()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<CustomerRepository>().As<ICustomerRepository>();
            builder.RegisterType<QueryProcessor>().As<IQueryProcessor>();

            builder.Register(c => new SelectCustomerQueryHandler())
                .As<IQueryHandler<SelectCustomerQuery, IEnumerable<Customer>>>();

            builder.RegisterType<Runner>();
            var container = builder.Build();

            var csl = new AutofacServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => csl);

            var runner = container.Resolve<Runner>();
            runner.Run(new SelectCustomerQuery());
        }
        public async Task Startup(Action<ContainerBuilder> buildDependencies = null)
        {
            await CommenceStartup();

            var builder = new ContainerBuilder();

            buildDependencies?.Invoke(builder);

            // Perform registrations and build the container.
            var container = builder.Build();

            await BuildCoreDependencies(container);

            // Set the service locator to an AutofacServiceLocator.
            var csl = new AutofacServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => csl);

            await CompleteStartup();
        }
Example #4
0
        public static void Init()
        {
            //Used to build an Autofac.IContainer from component registrations.
            var builder = new ContainerBuilder();

            // Register Components via their modules(contain registrations for components)
            builder.RegisterAssemblyModules(new[]{
                typeof(BridalPOS.Bootstrapper.ManagerRegistrar).Assembly,
                typeof(BridalPOS.Bootstrapper.RepositoryRegistrar).Assembly
            });

            // Create a new container with the component registrations that have been made.
            var container = builder.Build(Autofac.Builder.ContainerBuildOptions.None);

            //Autofac implementation of the Microsoft CommonServiceLocator.
            //The service locator provides a way to locate a service without specifying the concrete type. Another form of DI.
            var locator = new AutofacServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            var nav = new NavigationService();
            nav.Initialize((UINavigationController)Window.RootViewController);
            nav.Configure(Views.Main.ToString(), "MainView");
            nav.Configure(Views.Hello.ToString(), "HelloViewController");

            var builder = new ContainerBuilder();
            builder.RegisterInstance<INavigationService>(nav);

            builder.RegisterType<MainViewModel>();
            builder.RegisterType<HelloViewModel>();

            var container = builder.Build();

            var serviceLocator = new AutofacServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            return true;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if(!_isInitialized)
            {
                var nav = new NavigationService();
                nav.Configure(Core.Views.Main.ToString(), typeof(MainActivity));
                nav.Configure(Core.Views.Hello.ToString(), typeof(HelloActivity));

                var builder = new ContainerBuilder();
                builder.RegisterInstance<INavigationService>(nav);

                builder.RegisterType<MainViewModel>();
                builder.RegisterType<HelloViewModel>();

                var container = builder.Build();

                var serviceLocator = new AutofacServiceLocator(container);

                ServiceLocator.SetLocatorProvider(() => serviceLocator);

                _isInitialized = true;
            }

            ViewModel = ServiceLocator.Current.GetInstance<MainViewModel>();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            var button = FindViewById<Button>(Resource.Id.send);
            Text = FindViewById <EditText>(Resource.Id.name);

            this.SetBinding(() => ViewModel.Name,() => Text.Text, BindingMode.TwoWay);
            button.SetCommand("Click", ViewModel.Send);
        }
        protected void Application_Start()
        {
            // Register MVC-related dependencies.
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinderProvider();

            // Register the EntLib classes.
            builder.RegisterEnterpriseLibrary();

            // Set the MVC dependency resolver to use Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Set the EntLib service locator to use Autofac.
            var autofacLocator = new AutofacServiceLocator(container);
            EnterpriseLibraryContainer.Current = autofacLocator;

            // Finish initialization of MVC-related items.
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
Example #8
0
        public static void Run()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<CustomerRepository>().As<ICustomerRepository>();
            builder.RegisterType<BatchProcessor>().As<IBatchProcessor>();

            builder.Register(c => new SelectCustomerByIdQueryHandler())
                .As<IMultipleQueriesHandler<List<SelectCustomerByIdQuery>, IEnumerable<Customer>>>();

            builder.RegisterType<Runner>();
            var container = builder.Build();

            var csl = new AutofacServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => csl);
            var runner = container.Resolve<Runner>();

            var queries = new List<SelectCustomerByIdQuery>
            {
                new SelectCustomerByIdQuery() { Id =1  },
                new SelectCustomerByIdQuery() { Id =2  }
            };
            runner.RunAll(queries);
        }
Example #9
0
        /// <summary>
        /// Registers the set of types for the global container and service provider.
        /// </summary>
        /// <returns>A pre-configured IOC container.</returns>
        private static IContainer RegisterContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule<DeeplyRegistrationModule>();
            builder.RegisterModule<ConfigurationSettingsReader>();

            var container = builder.Build();

            var serviceLocator = new AutofacServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            return container;
        }
Example #10
0
        private static void Bootstrap()
        {
            System.Diagnostics.Debug.WriteLine("Bootstrap");

            if (_container == null)
            {
                var builder = new ContainerBuilder();

                // shared modules

                builder.RegisterModule<CoreModule>();

                // platform-specific registrations

                builder.RegisterType<DispatcherHelper>()
                    .AsSelf()
                    .As<IDispatcherHelper>()
                    .SingleInstance();

                builder.RegisterInstance(new Ble.Adapter())
                    .As<Ble.IAdapter>();

                var nav = new NavigationService();
                nav.Configure(ViewModelLocator.DeviceListViewKey, typeof(DeviceListViewActivity));
                nav.Configure(ViewModelLocator.DeviceViewKey, typeof(DeviceViewActivity));

                builder.RegisterInstance(nav)
                    .As<INavigationService>();

                builder.RegisterType<DialogService>()
                    .As<IDialogService>()
                    .SingleInstance();

                _container = builder.Build();
            }

            if (!ServiceLocator.IsLocationProviderSet)
            {
                var csl = new AutofacServiceLocator(_container);
                ServiceLocator.SetLocatorProvider(() => csl);
            }
        }
Example #11
0
        private void Bootstrap()
        {
            System.Diagnostics.Debug.WriteLine("Bootstrap");

            if (_container == null)
            {
                var builder = new ContainerBuilder();

                // shared modules

                builder.RegisterModule<CoreModule>();

                // platform-specific registrations

                builder.RegisterType<DispatcherHelper>()
                    .AsSelf()
                    .As<IDispatcherHelper>()
                    .SingleInstance();

                builder.RegisterInstance(Ble.Adapter.Current)
                    .As<Ble.IAdapter>();

                var nav = new NavigationService();
                nav.Initialize((UINavigationController)Window.RootViewController);
                nav.Configure(ViewModelLocator.DeviceListViewKey, "DeviceListViewController");
                nav.Configure(ViewModelLocator.DeviceViewKey, "DeviceViewController");
                nav.Configure(ModeSmsViewKey, "ModeSmsViewController");
                nav.Configure(ModeSmsStatusViewKey, "ModeSmsStatusViewController");
                nav.Configure(ModePanoViewKey, "ModePanoViewController");
                nav.Configure(ModePanoStatusViewKey, "ModePanoStatusViewController");
                nav.Configure(ModeAstroViewKey, "ModeAstroViewController");
                nav.Configure(ModeAstroStatusViewKey, "ModeAstroStatusViewController");
                nav.Configure(JoystickViewKey, "JoystickViewController");

                builder.RegisterInstance(nav)
                    .As<INavigationService>();

                builder.RegisterType<DialogService>()
                    .As<IDialogService>()
                    .SingleInstance();

                _container = builder.Build();
            }

            if (!ServiceLocator.IsLocationProviderSet)
            {
                var csl = new AutofacServiceLocator(_container);
                ServiceLocator.SetLocatorProvider(() => csl);
            }
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleContextFixture"/> class.
        /// </summary>
        /// <remarks>This constructor is normally used when instantiated in-test.</remarks>
        /// <param name="registerTypes">Call-back function allowing the user to register additional classes.</param>
        public SimpleContextFixture(Action<ContainerBuilder> registerTypes)
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<ConsoleExecutionLog>().As<IExecutionLog>();

            if (registerTypes != null)
            {
                registerTypes(builder);
            }

            var container = builder.Build();
            var locator = new AutofacServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);

            this.fixture = new Fixture();

            this.cancellationTokenSource = new CancellationTokenSource();

            this.context = new TaskContext(this.cancellationTokenSource);
        }
Example #13
0
        // Do not add any additional code to this method
        private void InitializePhoneApplication()
        {
            if (phoneApplicationInitialized)
                return;

            // Create the frame but don't set it as RootVisual yet; this allows the splash
            // screen to remain active until the application is ready to render.
            RootFrame = new PhoneApplicationFrame();
            RootFrame.Navigated += CompleteInitializePhoneApplication;

            // Handle navigation failures
            RootFrame.NavigationFailed += RootFrame_NavigationFailed;

            // Handle reset requests for clearing the backstack
            RootFrame.Navigated += CheckForResetNavigation;

            // Handle contract activation such as a file open or save picker
            PhoneApplicationService.Current.ContractActivated += Application_ContractActivated;

            // Ensure we don't initialize again
            phoneApplicationInitialized = true;

            CopyDatabase();

            var builder = new ContainerBuilder();

            builder.RegisterModule(new OwModule());

            IContainer container = builder.Build();

            var locator = new AutofacServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);

            var session = ServiceLocator.Current
                .GetInstance<Session>();

            session.LoadData();

            var chatManager = ServiceLocator.Current
                .GetInstance<ChatManager>();

            chatManager.Initialize();

            if (session.User != null)
            {
                RootFrame.Navigate(new Uri("/View/MainPage.xaml", UriKind.RelativeOrAbsolute));
            }
            else
            {
                RootFrame.Navigate(new Uri("/View/LoginPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }