private UnityServiceRegistry(UnityServiceRegistry parent) { _parent = parent; _container = _parent != null ? _parent._container.CreateChildContainer() : new UnityContainer(); _container.RegisterInstance<IServiceRegistry>(this); _locator = new UnityServiceLocator(_container, _parent != null ? _parent._locator : null); _container.RegisterInstance<IServiceLocator>(Locator); }
public void AfterDisposingTheContainerTheServiceLocatorCanResolved() { UnityContainer container = GetNewContainer(); IServiceLocator sl = new UnityServiceLocator(container); container.RegisterType <IService, Service>(); AssertEx.ShouldNotThrow(() => sl.GetInstance <IService>()); container.Dispose(); AssertEx.ShouldNotThrow(() => sl.GetInstance <IService>()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); Database.SetInitializer <SchoolContext>(new SchoolInitializer()); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); IUnityContainer container = GetUnityContainer(); var serviceLocator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => serviceLocator); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); }
/// <summary> /// Registers the dependency resolver. /// </summary> /// <param name="config">The configuration.</param> private static void RegisterDependencyResolver(HttpConfiguration config) { var container = new UnityContainer(); Bootstraper.Register(container); config.DependencyResolver = new UnityResolver(container); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public void InitializeIOCContainer() { IOCContainer = new UnityContainer(); var unityServiceLocator = new UnityServiceLocator(IOCContainer); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); IOCContainer.RegisterInstance(this); IOCContainer.RegisterType <IChatService, MimicBotService>(); IOCContainer.RegisterType <InteractionPageVM>(); }
protected override Task OnInitializeAsync(IActivatedEventArgs args) { var locator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => locator); _container.RegisterInstance(SessionStateService); _container.RegisterInstance(NavigationService); _container.RegisterInstance(_regionManager); _container.RegisterInstance<IEventAggregator>(new EventAggregator()); ViewModelLocationProvider.SetDefaultViewModelFactory(viewModelType => _container.Resolve(viewModelType)); InizializeRegionManager(); return Task.FromResult<object>(null); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var container = new UnityContainer(); container.RegisterInstance <IUnityContainer>(container); container.RegisterType <ITimerService, TimerService>(); UnityServiceLocator locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public void DisposingTheContainerDoesNotCrashWhenTheServiceLocatorInstanceIsRegisteredByTheAdapterOnly() { UnityContainer container = GetNewContainer(); IServiceLocator sl = new UnityServiceLocator(container); container.RegisterType <IService, Service>(); AssertEx.ShouldNotThrow(() => sl.GetInstance <IService>()); Action act = container.Dispose; act.ShouldNotThrow(); // this will not trigger sl.Dispose() because the sl instance is not controlled by the container }
/// <summary> /// Awake Unity method. /// </summary> private void Awake() { try { unityServiceLocator = UnityServiceLocator.Instance as UnityServiceLocator; RegisterServices(); } catch (Exception e) { UnityEngine.Debug.LogException(e); } }
public ViewModelLocator() { _unityContainer = new UnityContainer(); _unityContainer.RegisterType <IActualPriceService, ActualPriceService>(); _unityContainer.RegisterType <IMarketPriceService, MarketPriceService>(); _unityContainer.RegisterType <MainVieWModel>(new ContainerControlledLifetimeManager()); _unityContainer.RegisterType <ListViewModel>(new ContainerControlledLifetimeManager()); UnityServiceLocator unityServiceLocator = new UnityServiceLocator(_unityContainer); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); }
public void Run() { ResourceRegistrator.Initialization(); UnityContainer = new UnityContainer(); UnityContainer.RegisterType <ISettingsService, SettingsService>(new ContainerControlledLifetimeManager(), new InjectionConstructor(StringFormatter.GetAppDataFolderPath())); ModelBootstrapper.ConfigureContainer(UnityContainer); var locator = new UnityServiceLocator(UnityContainer); ServiceLocator.SetLocatorProvider(() => locator); }
public App() { this.InitializeComponent(); this.SplashFactory = (e) => new Splash(e); var settings = SettingsService.Instance; this.RequestedTheme = settings.AppTheme; this.CacheMaxDuration = settings.CacheMaxDuration; this.ShowShellBackButton = settings.UseShellBackButton; IServiceLocator locator = new UnityServiceLocator(this.container); ServiceLocator.SetLocatorProvider(() => locator); }
private static void ResolveDependencies() { UnityContainer lContainer = new UnityContainer(); UnityConfigurationSection lSection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); lSection.Containers["containerOne"].Configure(lContainer); UnityServiceLocator locator = new UnityServiceLocator(lContainer); ServiceLocator.SetLocatorProvider(() => locator); // NEW CODE locator.GetInstance <EmailService.Services.EmailService>().startTimer(2000); }
public void Setup() { this.callCounter = new CallCounter(); var container = new UnityContainer(); container.AddNewExtension <Interception>(); container.AddNewExtension <TransientPolicyBuildUpExtension>(); container.RegisterInstance <CallCounter>(this.callCounter); var serviceLocator = new UnityServiceLocator(container); this.policyInjector = new PolicyInjector(serviceLocator); }
/// <summary> /// Registers the type mappings with the Unity container. /// </summary> /// <param name="container">The unity container to configure.</param> /// <remarks> /// There is no need to register concrete types such as controllers or /// API controllers (unless you want to change the defaults), as Unity /// allows resolving a concrete type even if it was not previously /// registered. /// </remarks> public static void RegisterTypes(IUnityContainer container) { var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); container.RegisterType <IOrderService, OrderService>(); container.RegisterType(typeof(IDocumentDbRepository <>), typeof(DocumentDbRepository <>)); GlobalConfiguration.Configuration.DependencyResolver = new Unity.AspNet.WebApi.UnityDependencyResolver(container); }
public ViewModelLocator() { _container = new UnityContainer(); _container.RegisterType <IHttpClientWrapper, HttpClientWrapper>(); _container.RegisterType <IToDoApiServiceAgent, ToDoApiServiceAgent>(); _container.RegisterType <IToDoService, ToDoService>(); _container.RegisterType <IPageService, PageService>(); _container.RegisterType <ToDoListViewModel>(new ContainerControlledLifetimeManager()); var unityServiceLocator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); }
public void AfterDisposingTheContainerAndTheServiceLocatorResultsInObjectDisposedExceptionWhenResolving() { UnityContainer container = GetNewContainer(); IServiceLocator sl = new UnityServiceLocator(container); container.RegisterType <IService, Service>(); AssertEx.ShouldNotThrow(() => sl.GetInstance <IService>()); container.Dispose(); ((IDisposable)sl).Dispose(); AssertEx.ShouldThrow(() => sl.GetInstance <IService>()); }
protected void Application_Start() { var container = new UnityContainer(); container.RegisterType <IService, Service>("HttpRequestLifetimeManager", new HttpRequestLifetimeManager(), new InjectionFactory(c => new Service(HttpContext.Current.Request.QueryString["Name"]))) .RegisterType <IService, Service>("ContainerControlledLifetimeManager", new ContainerControlledLifetimeManager(), new InjectionFactory(c => new Service(HttpContext.Current.Request.QueryString["Name"]))) .RegisterType <IService, Service>("HttpApplicationLifetimeManager", new HttpApplicationLifetimeManager(), new InjectionFactory(c => new Service(HttpContext.Current.Request.QueryString["Name"]))) .RegisterType <IService, Service>("HttpSessionLifetimeManager", new HttpSessionLifetimeManager(), new InjectionFactory(c => new Service(HttpContext.Current.Request.QueryString["Name"]))); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public App() { InitializeComponent(); ApplicationIinitializer.InitDatabase(); var tabbedPage = new MainTabbedView(); MainPage = tabbedPage; var unityServiceLocator = new UnityServiceLocator(ContainerInitializer.InitializeContainer()); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); }
public App() { var unityContainer = new UnityContainer(); unityContainer .ConfigureWithDbContext() .ConfigureWithRepository(); var unityServiceLocator = new UnityServiceLocator(unityContainer); var serviceLocator = new ServiceLocatorProvider(() => unityServiceLocator); ServiceLocator.SetLocatorProvider(serviceLocator); }
public static void Initialize() { var container = new UnityContainer(); container.RegisterType <IEmployeee, EmployeeeRepo>(); ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(container)); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public static void Init() { unityContainer = new UnityContainer(); unityContainer.RegisterType <IDialogService, IOSDialogService>(); unityContainer.RegisterType <ILocalNotificationsManager, iOSLocalNotificationsManager>(new ContainerControlledLifetimeManager()); unityContainer.RegisterType <IApiDataHelper, IOSApiDataHelperHandler>(); CommonDependencyInjectionConfig.Init(unityContainer); UnityServiceLocator unityServiceLocalter = new UnityServiceLocator(unityContainer); CommonServiceLocator.ServiceLocator.SetLocatorProvider(() => unityServiceLocalter); }
public UnityConfig() { IUnityContainer unityContainer = new UnityContainer(); unityContainer.RegisterType <IRepositoryService, RepositoryService>(); unityContainer.RegisterType <IPullRequestService, PullRequestService>(); // ViewModels unityContainer.RegisterInstance(typeof(RepositoriesViewModel)); unityContainer.RegisterInstance(typeof(PullRequestsViewModel)); // Service Locator var unityServiceLocator = new UnityServiceLocator(unityContainer); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); }
public static void InitializeIoC() { try { IUnityContainer Container = Res365Container.Instance; UnityServiceLocator locator = new UnityServiceLocator(Container); ServiceLocator.SetLocatorProvider(() => locator); Container.AddNewExtension <Res365BusinessLogicExtension>(); } catch (Exception ex) { Console.WriteLine($"Error encountered initializing IOC container. {ex.Message}"); } }
public App() { InitializeComponent(); var unityContainer = new UnityContainer(); // register dependencies unityContainer.RegisterType <IProductsService, ProductsService>(); var unityServiceLocator = new UnityServiceLocator(unityContainer); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); MainPage = new MainPage(); }
private void ConfigureContainer() { var unityContainer = new UnityContainer(); unityContainer.RegisterType <IEventAggregator, EventAggregator>(); var dataService = Substitute.For <IDataService>(); unityContainer.RegisterInstance(dataService); var locator = new UnityServiceLocator(unityContainer); ServiceLocator.SetLocatorProvider(() => locator); }
public void DisposingTheContainerDoesCrashWhenTheServiceLocatorInstanceIsRegisteredWithContainerControlledLifetime() { UnityContainer container = GetNewContainer(); IServiceLocator sl = new UnityServiceLocator(container); container.RegisterInstance(sl); container.RegisterType <IService, Service>(); AssertEx.ShouldNotThrow(() => sl.GetInstance <IService>()); Action act = container.Dispose; act.ShouldThrow <StackOverflowException>(); // this will trigger sl.Dispose(), which triggers container.Dispose() which turns into a StackOverflowException }
public static void RegisterDependencies() { var container = new UnityContainer(); // service container.RegisterType <IImageService, ImageService>(new ContainerControlledLifetimeManager()); // viewmodel container.RegisterType <ImageViewModel>(new ContainerControlledLifetimeManager()); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
protected override void OnStartup(StartupEventArgs e) { var container = new UnityContainer(); container.RegisterSingleton <IMessageBoxService, MessageBoxService>(); container.RegisterSingleton <IDialogService, DialogService>(); container.RegisterSingleton <IDirectoryService, DirectoryService>(); container.RegisterSingleton <IModelConversionService <DirectoryModel, TransferDirectory>, DirectoryConversionService>(); container.RegisterSingleton <ISentinelDirectoryService, SentinelDirectoryService>(); UnityServiceLocator locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public static void Initialize() { var container = new UnityContainer(); // services container.RegisterInstance(new OpenWeatherMapService(Credentials.ApiKey)); // viewmodels container.RegisterType <WeatherViewModel>(new ContainerControlledLifetimeManager()); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public void Assert_False_If_Email_Does_Not_Exists() { //var uow = Mock.Create<IQTecUnitOfWork>(); //Mock.Arrange(() => uow.EmployeeRepository.IsEmailDuplicate("*****@*****.**")).CallOriginal(); var svcLocator = new UnityServiceLocator(container); var uow = svcLocator.GetInstance <IQTecUnitOfWork>(); var classunderTest = new EmployeeManager(uow); const bool ExpectedValue = false; var actualValue = classunderTest.IsEmailUnique("*****@*****.**"); Assert.AreEqual(ExpectedValue, actualValue); }
public void op_DoGetAllInstances_Type() { var expected = new Mock<ITest>().Object; var container = new Mock<IUnityContainer>(); container .Setup(x => x.ResolveAll(typeof(ITest))) .Returns(new[] { expected }) .Verifiable(); var obj = new UnityServiceLocator(container.Object); var actual = obj.GetAllInstances<ITest>().First(); Assert.Same(expected, actual); container.VerifyAll(); }
public void op_DoGetInstance_Type_string() { const string key = "example"; var expected = new Mock<ITest>().Object; var container = new Mock<IUnityContainer>(); container .Setup(x => x.Resolve(typeof(ITest), key)) .Returns(expected) .Verifiable(); var obj = new UnityServiceLocator(container.Object); var actual = obj.GetInstance<ITest>(key); Assert.Same(expected, actual); container.VerifyAll(); }
public void Regist() { var locator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => locator); }
public void GivenIHaveAUnityContainer() { IServiceLocator serviceLocator = new UnityServiceLocator(); UseThisServiceLocator(serviceLocator); }
public void Run(IBootLogger bootLogger, IPathMapper pathMapper) { var logger = new ServerBootLoggerAdapter(bootLogger); logger.Log("Bootstrapper starting...", Category.Info, Priority.None); try { logger.Log("Creating services container " + typeof(UnityServiceLocator).FullName, Category.Debug, Priority.None); var serviceLocator = new UnityServiceLocator(null, logger); logger.Log("Setting service locator provider", Category.Debug, Priority.None); //registrar o ServiceLocator ServiceLocator.SetLocatorProvider(() => serviceLocator); //registrar o locator ServiceLocator.Register<IServiceLocator>(serviceLocator); // registrar o path mapper ServiceLocator.Register<IPathMapper>(pathMapper); var workServicesManager = new WorkerServicesManager(); workServicesManager.Start(); ServiceLocator.Register<IWorkerServicesManager>(workServicesManager); // registrar o gerenciador de 'EntityStores' ServiceLocator.Register<IEntityStoreManager>(new EntityStoreManager()); // registrar o buffer do logger ServiceLocator.Register<LogWriterBufferService, LogWriterBufferService>(true); // registrar o factory de logs para o entity store ServiceLocator.Register<ILoggerFactory>(new EntityStoreLoggerFactory()); // registrar o gerenciador de log ServiceLocator.Register<ILogManager>(new LogManager()); // registrar o logger do sistema ServiceLocator.GetInstance<ILogManager>().RegisterLogger(logger); // registrar o servico de gerenciamento de usuarios serviceLocator.Register<IAccountService, AccountService>(true); // serviços de autenticacao e autorização ServiceLocator.Register<IAuthenticationService, AuthenticationService>(true); ServiceLocator.Register<IAuthorizationService, AuthorizationService>(true); // registrar o pipeline serviceLocator.Register<IPipelineManager, PipelineManager>(true); // registrar o worker que fará a gravação do log ServiceLocator.GetInstance<IWorkerServicesManager>().RegisterService( "LogWriter", new LogWriterWorkerService(), null); //agregador de eventos ServiceLocator.Register<IEventAggregator, EventAggregator>(true); // controlador de sessoes serviceLocator.Register<IClientSessionManager, ClientSessionManager>(true); // recursos do cliente serviceLocator.Register<IResourceMapService, ResourceMapService>(true); //registrar os servicos de modulos ServiceLocator.Register<IModuleCatalog>(new DirectoryModuleCatalog2(pathMapper.MapPath("~/bin"))); ServiceLocator.Register<IModuleInitializer, ModuleInitializer>(true); ServiceLocator.Register<IModuleManager, ModuleManager>(true); //localizador de controllers mvc //ServiceLocator.Register<IMvcControllerTypeLocator, MvcControllerTypeLocator>(true); //System.Web.Mvc.ControllerBuilder.Current.SetControllerFactory(new MvcControllerFactory()); logger.Log("Loading modules...", Category.Info, Priority.None); //carregar os modulos ServiceLocator.GetInstance<IModuleManager>().Run(); logger.Log("Server started", Category.Info, Priority.None); ServiceLocator.GetInstance<ILogManager>() .GetLogger("START_UP") .Log("Server started", Category.Debug, Priority.None); } catch (Exception ex) { logger.LogException("Fatal error on server bootstrap", ex, Priority.High); } }
public UnityServiceLocator(IUnityContainer container, UnityServiceLocator parent) { _container = container; _parent = parent; }
public MvcApplication() { var locator = new UnityServiceLocator(); locator.Register<IServiceLocator>(locator); ServiceLocatorManager.SetLocatorProvider(() => locator); }
private EventStore CreateEventStore(IUnityContainer arg) { if (handlerTypes != null) { var locator = new UnityServiceLocator(arg); return new EventStore(locator).SetReadModelTypes(handlerTypes) .Initialize((IDocumentStore)locator.Resolve(typeof(IDocumentStore))); } var serviceLocator = new UnityServiceLocator(Container); return new EventStore(serviceLocator).SetReadModelTypes(handlers.Select(x => x.GetType())) .Initialize( (IDocumentStore)serviceLocator.Resolve(typeof(IDocumentStore))); }