static ApiSetup() { try { //Create Container = new UnityContainer(); Locator = new UnityServiceLocator(Container); //Add entlib extensions Container.AddNewExtension<EnterpriseLibraryCoreExtension>(); #pragma warning disable 612,618 Container.AddNewExtension<CachingBlockExtension>(); #pragma warning restore 612,618 ServiceLocator.SetLocatorProvider(() => Locator); Container.LoadConfiguration("api"); ApiDefaultConfig.DoDefaultRegistrations(Container); //NOTE: disabled for now //try //{ // ApiDefaultConfig.DoAutomaticConfiguration(Container); // Initialization.Add(ApiSetupState.UnityAutoRegitrations, null); //} //catch (Exception e) //{ // Initialization.Add(ApiSetupState.UnityAutoRegitrations, new[] { e }); //} } catch (Exception e) { Initialization.Add(ApiSetupState.UnityRegitrations, new[] { e }); throw; } Initialization.Add(ApiSetupState.UnityRegitrations, null); }
public static void RegisterComponents() { var container = new UnityContainer(); container.RegisterType(typeof(IDroughtMonitorRepository), typeof(DroughtMonitorRepository), new InjectionConstructor(ConfigurationManager.ConnectionStrings["DMConnection"].ConnectionString)); container.RegisterType(typeof(IWaterDataRepository), typeof(WaterDataRepository), new InjectionConstructor(ConfigurationManager.ConnectionStrings["WaterDBConnection"].ConnectionString)); container.RegisterType(typeof(IPhotoRepository), typeof(PhotoRepository), new InjectionConstructor(ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString)); container.RegisterType(typeof(IPhotoService), typeof(PhotoService)); container.RegisterType(typeof(ISearchService), typeof(SearchService)); container.RegisterType(typeof(ICollectionService), typeof(CollectionService)); container.RegisterType(typeof(IUnitOfWork), typeof(UnitOfWork)); container.RegisterType(typeof(IEntityRepository<>), typeof(EntityRepository<>)); container.RegisterType(typeof(DbContext), typeof(ApplicationContext)); DroughtMonitorImporter.InitWithContainer(container); WaterDataImporter.InitWithContainer(container); container.RegisterInstance(new ApplicationContextAdapter(container.Resolve<DbContext>()), new HierarchicalLifetimeManager()); container.RegisterType<IDbSetFactory>(new InjectionFactory(con => con.Resolve<ApplicationContextAdapter>())); container.RegisterType<IDbContext>(new InjectionFactory(con => con.Resolve<ApplicationContextAdapter>())); DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container); UnityServiceLocator locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); _container = new UnityContainer(); _container.RegisterInstance<IUnityContainer>(_container); var locator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => locator); _container.RegisterType<UserProvider>(new ContainerControlledLifetimeManager()); _container.RegisterType<IChildViewModelManager, ChildViewModelManager>(new ContainerControlledLifetimeManager()); _container.RegisterType<UserDetailsViewModel>(new ContainerControlledLifetimeManager()); _container.RegisterType<UserListViewModel>(new ContainerControlledLifetimeManager()); var mappingResolver = new MappingViewTypeResolver(); mappingResolver.RegisterTypeMapping<UserDetailsView, UserDetailsViewModel>(); mappingResolver.RegisterTypeMapping<UserListView, UserListViewModel>(); mappingResolver.RegisterTypeMapping<UserDetailsWindow, UserDetailsWindowViewModel>(); _container.RegisterInstance<IViewTypeResolver>(mappingResolver); var mainVM = _container.Resolve<MainWindowViewModel>(); mainVM.Initialize(); var mainWindow = new MainWindow(); mainWindow.DataContext = mainVM; mainWindow.Show(); }
static void Main() { logger.Info("--------AppForApproversLevel1 Unity Container--------"); var container = new UnityContainer(); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); logger.Info("--------AppForApproversLevel1 IBus Config--------"); Configure.With() .UnityBuilder(container) .UseTransport<Msmq>() .DisableTimeoutManager() .UnicastBus() .CreateBus() .Start(StartupAction); var items = new BindingList<ItemViewModel>(); System.Console.WriteLine("AppForApproversLevel1"); foreach (var item in items) { System.Console.WriteLine(item.ToString()); } var appForm = new MainForm(items); var context = new Context<ItemViewModel> { Items = items, AppForm = appForm }; container.RegisterInstance(context); Application.EnableVisualStyles(); Application.Run(context.AppForm); }
public UnityTests() { var container = new UnityContainer(); container.RegisterTypes(AllClasses.FromAssemblies(typeof(A).Assembly), WithMappings.FromAllInterfaces, overwriteExistingMappings: true); ServiceLocator = new UnityServiceLocator(container); }
private void InitializeDependencyInjectionContainer() { container = new UnityContainerFactory().CreateConfiguredContainer(); var serviceLocator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => serviceLocator); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); }
private static void Initialize() { var profile = new AutoMapperProfile(); Mapper.AddProfile(profile); Mapper.AssertConfigurationIsValid(profile.ProfileName); Database.DefaultConnectionFactory = new ConnectionFactory(Database.DefaultConnectionFactory); Database.SetInitializer<SketchDbContext>(null); Database.SetInitializer<EventStoreDbContext>(null); using (var sketchDbContext = new SketchDbContext()) using (var eventStoreDbContext = new EventStoreDbContext()) { if (!sketchDbContext.Database.Exists()) { ((IObjectContextAdapter)sketchDbContext).ObjectContext.CreateDatabase(); eventStoreDbContext.Database.ExecuteSqlCommand(((IObjectContextAdapter)eventStoreDbContext).ObjectContext.CreateDatabaseScript()); } } var container = new UnityContainer(); var unityServiceLocator = new UnityServiceLocator(container); Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => unityServiceLocator); ServiceLocator = Microsoft.Practices.ServiceLocation.ServiceLocator.Current; new Core.Module().Init(container); new Module().Init(container); }
private void ConfigurationContainers() { _container = new UnityContainer(); _container .RegisterType<IDataServicesProviderFactory, SqlCeDataServicesProviderFactory>(new ContainerControlledLifetimeManager()) .RegisterType<ISessionLocator, SessionLocator>(new ContainerControlledLifetimeManager()) .RegisterType<ITransactionManager, TransactionManager>() .RegisterType<IDataMigrationManager, DataMigrationManager>() .RegisterType<IAutomappingConfigurer, FileAutomappingConfigurer>(new PerThreadLifetimeManager()) .RegisterType<ISessionFactoryHolder, SessionFactoryHolder>(new ContainerControlledLifetimeManager()) .RegisterType(typeof(IRepository<>), typeof(Repository<>)) .RegisterType<IDataMigrationInterpreter, DefaultDataMigrationInterpreter>() .RegisterType<ILogger, NullLogger>() .RegisterType<IWorkEnvironment, WorkEnvironment>(new ContainerControlledLifetimeManager()) .RegisterInstance<IUnityContainer>(_container) .RegisterInstance<IDataMigrationDiscoverer>(new DataMigrationDiscoverer()) .RegisterInstance<ShellSettings>( new ShellSettings { DatabaseName = "GymnastikaTest.sdf", DataFolder = Directory.GetCurrentDirectory(), DataProvider = "SqlCe", }); _serviceLocator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => _serviceLocator); }
public App() { var path = Path.GetDirectoryName(GetType().Assembly.Location).Trim('\\'); var connectionString = ConfigurationManager.ConnectionStrings["ApplicationDb"].ConnectionString .Replace("|DataDirectory|", Path.Combine(path, "App_Data")); var container = new UnityContainer(); container.RegisterType<ApplicationDbContext>( new InjectionConstructor(connectionString)); container.RegisterType<MainViewModel>(); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); Mapper.CreateMap<Product, ProductViewModel>() .ForMember(ex => ex.Error, opt => opt.Ignore()) .ForMember(ex => ex.IsValid, opt => opt.Ignore()) .ForMember(ex => ex.IsInDesignMode, opt => opt.Ignore()); Mapper.CreateMap<ProductViewModel, Product>() .ForMember(pr => pr.ProductId, opt => opt.Ignore()); }
private static IUnityContainer ConfigureContainer(IServiceProvider package, ServiceLocatorOptions options) { if (package == null) throw new ArgumentNullException(nameof(package), $"{nameof(package)} is null."); IUnityContainer container = new UnityContainer(); container.AddExtension(new ServiceProviderUnityExtension(package, options)); container.RegisterType<IToolkit, TookitImpl>(new ContainerControlledLifetimeManager()); container.RegisterTypes(new SolutionExplorerNodeFactoryRegistrationConvention()); container.RegisterType<IEnumerable<ISolutionExplorerNodeFactory>, ISolutionExplorerNodeFactory[]>(); container.RegisterType<ISolutionExplorerNodeFactory, GlobalSolutionExplorerNodeFactory>(); container.RegisterType<ISolutionExplorer, SolutionExplorer>(); container.RegisterType<IOutputWindow, OutputWindow>(new ContainerControlledLifetimeManager()); container.RegisterType<IDialogService, DialogService>(new ContainerControlledLifetimeManager()); container.RegisterType<IEnumerable<ICommandImplementation>, ICommandImplementation[]>(); container.RegisterInstance<IServiceProvider>(package); container.RegisterType<ICommandManager, CommandManager>(new ContainerControlledLifetimeManager()); UnityServiceLocator serviceLocator = new UnityServiceLocator(container); container.RegisterInstance<IServiceLocator>(serviceLocator); if (!ServiceLocator.IsLocationProviderSet) ServiceLocator.SetLocatorProvider(() => serviceLocator); return container; }
public void SetUp() { string dbPath = Path.Combine(_dbFolder, DbName); if (File.Exists(dbPath)) { File.Delete(dbPath); } _container = new UnityContainer(); _container .RegisterType<IDataServicesProviderFactory, SqlCeDataServicesProviderFactory>(new ContainerControlledLifetimeManager()) .RegisterType<ISessionLocator, SessionLocator>(new ContainerControlledLifetimeManager()) .RegisterType<ITransactionManager, TransactionManager>() .RegisterType<IDataMigrationManager, DataMigrationManager>() .RegisterType<IAutomappingConfigurer, MockAutomappingConfigurer>(new PerThreadLifetimeManager()) .RegisterType<ISessionFactoryHolder, SessionFactoryHolder>(new ContainerControlledLifetimeManager()) .RegisterType(typeof(IRepository<>), typeof(Repository<>)) .RegisterType<IDataMigrationInterpreter, DefaultDataMigrationInterpreter>() .RegisterType<ILogger, FileLogger>() .RegisterType<IWorkEnvironment, WorkEnvironment>(new ContainerControlledLifetimeManager()) .RegisterInstance(new DataMigrationDiscoverer().AddFromAssemblyOf<DataMigrationManagerTests>()) .RegisterInstance( new ShellSettings { DatabaseName = DbName, DataFolder = _dbFolder, DataProvider = "SqlCe" }); _serviceLocator = new UnityServiceLocator(_container); ServiceLocator.SetLocatorProvider(() => _serviceLocator); }
protected override void ConfigureServiceLocator() { base.ConfigureServiceLocator(); var serviceLocator = new UnityServiceLocator(this.Container); this.Container.RegisterInstance(serviceLocator); }
public override bool OnStart() { Trace.TraceInformation("Starting Worker Role"); // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. Database.DefaultConnectionFactory = new ConnectionFactory(Database.DefaultConnectionFactory); var profile = new AutoMapperProfile(); Mapper.AddProfile(profile); Mapper.AssertConfigurationIsValid(profile.ProfileName); var container = new UnityContainer(); var unityServiceLocator = new UnityServiceLocator(container); Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => unityServiceLocator); ServiceLocator = Microsoft.Practices.ServiceLocation.ServiceLocator.Current; new Sketch.Core.Module().Init(container); new Module().Init(container); return base.OnStart(); }
/// <summary> /// Initializes the <see cref="ServiceLocator" />. /// </summary> public static void Init() { Container = new UnityContainer(); Registries = new List<IRegistry>(); var serviceLocator = new UnityServiceLocator(Container); ServiceLocator.SetLocatorProvider(() => serviceLocator); }
public App() { UnityServiceLocator locator = new UnityServiceLocator(ConfigureUnityContainer()); ServiceLocator.SetLocatorProvider(() => locator); MainWindow = ServiceLocator.Current.GetInstance<MainWindow>(); MainWindow.Show(); }
protected void Application_Start(object sender, EventArgs e) { UnityContainer unityContainer = new UnityContainer(); unityContainer.RegisterType<IExceptionDetailFactory, ExceptionDetailFactory<UpdateException>>(typeof(UpdateException).FullName, new InjectionConstructor(new object[] { (Func<UpdateException, IExceptionDetail>)(ue => new UpdateExceptionDetail(ue)) })); UnityServiceLocator serviceLocator = new UnityServiceLocator(unityContainer); ServiceLocator.SetLocatorProvider(() => serviceLocator); }
public static IUnityContainer Initialize() { var container = BuildUnityContainer(); var locator = new UnityServiceLocator(container); //set the CSL-compliant service locator - forces the unity initialization ServiceLocator.SetLocatorProvider(() => locator); return container; }
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); }
private static void Initialize() { var container = new UnityContainer(); var unityServiceLocator = new UnityServiceLocator(container); Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => unityServiceLocator); ServiceLocator = Microsoft.Practices.ServiceLocation.ServiceLocator.Current; new Core.Module().Init(container); new Module().Init(container); }
public void Configure() { Trace.WriteIf(Tracing.Is.TraceVerbose, string.Empty); IUnityContainer container = new UnityContainer(); ((UnityConfigurationSection)ConfigurationManager.GetSection("unity")).Configure(container, "container"); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public static void RegisterIoc(HttpConfiguration config) { IServiceLocator serviceLocator = new UnityServiceLocator(container); EnterpriseLibraryContainer.Current = serviceLocator; System.Web.Mvc.DependencyResolver.SetResolver(new Unity.Mvc3.UnityDependencyResolver(container)); config.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container); }
/// <summary> /// Initializes the unity container when the application starts up. /// </summary> /// <remarks> /// Do not edit this method. Perform any modifications in the /// <see cref="RegisterDependencies" /> method. /// </remarks> internal static void PostStart() { IUnityContainer container = new UnityContainer(); HttpContext.Current.Application.SetContainer( container ); RegisterDependencies( container ); var locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
public static IUnityContainer Initialise() { var container = BuildUnityContainer(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); UnityServiceLocator locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); return container; }
private void ConfigureUnity() { Container = new UnityContainer(); Container.LoadConfiguration(); UnityServiceLocator locator = new UnityServiceLocator(Container); ServiceLocator.SetLocatorProvider(() => locator); ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(Container)); }
public static IUnityContainer CreateAndRegisterUnityContainer() { IUnityContainer unityContainer = new UnityContainer(); UnityServiceLocator serviceLocator = new UnityServiceLocator(unityContainer); ServiceLocator.SetLocatorProvider(() => serviceLocator); return unityContainer; }
private void RegisterIoc() { UnityContainer container = new UnityContainer(); container.RegisterType<GnomesContext, GnomesContext>(); ApplicationUnityRegistrator registrator = new ApplicationUnityRegistrator(); registrator.Register(container); UnityServiceLocator locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); }
static Program() { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += CurrentDomain_UnhandledException; container = new UnityContainer(); var unityServiceLocator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => unityServiceLocator); container.RegisterType<MangaDataContext>("SitesContext"); LogPath = String.Format("ApplicationSessionLog_{0:yyyyMMddHHmmss}.log", DateTime.Now); Logger.LogAction = LogCallback; }
/// <summary> /// Creates the instance of the Unity container. /// </summary> protected override void PreCompose() { unityContainer = new UnityContainer(); var locator = new UnityServiceLocator(unityContainer); exportProvider = new CSLExportProvider(locator); unityContainer.AddExtension(new CSLExportProviderExtension(exportProvider)); RegisterTypes(); }
/// <summary> /// Initializes a new instance of the <see cref="FakeRepositaryTest" /> class. /// </summary> public FakeRepositaryTest() { IUnityContainer container = new UnityContainer(); container.RegisterType<IRepositary<SimpleEntity>, FakeRepositary<SimpleEntity>>( new PerThreadLifetimeManager()); container.RegisterType<IRepositary<AggregationEntity>, FakeRepositary<AggregationEntity>>( new PerThreadLifetimeManager()); var serviceProvider = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => serviceProvider); }
public static IUnityContainer Compose() { var container = new UnityContainer() .AddNewExtension<ApplicationInitializer>() .AddNewExtension<CoreInitializer>() .AddNewExtension<ServicesInitializer>(); UnityServiceLocator locator = new UnityServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); return container; }
private void SetIoc() { Microsoft.Practices.Unity.UnityServiceLocator locator = new Microsoft.Practices.Unity.UnityServiceLocator(ConfigureUnityContainer()); ServiceLocator.SetLocatorProvider(() => locator); }