Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 6
0
 private void InitializeDependencyInjectionContainer()
 {
     container = new UnityContainerFactory().CreateConfiguredContainer();
     var serviceLocator = new UnityServiceLocator(container);
     ServiceLocator.SetLocatorProvider(() => serviceLocator);
     DependencyResolver.SetResolver(new UnityDependencyResolver(container));
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
      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);
        }
Exemplo n.º 12
0
        protected override void ConfigureServiceLocator()
        {
            base.ConfigureServiceLocator();

            var serviceLocator = new UnityServiceLocator(this.Container);
            this.Container.RegisterInstance(serviceLocator);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 15
0
        public App()
        {
            UnityServiceLocator locator = new UnityServiceLocator(ConfigureUnityContainer());
            ServiceLocator.SetLocatorProvider(() => locator);

            MainWindow = ServiceLocator.Current.GetInstance<MainWindow>();
            MainWindow.Show();
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
		/// <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);
		}
Exemplo n.º 23
0
        public static IUnityContainer Initialise()
        {
            var container = BuildUnityContainer();
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            UnityServiceLocator locator = new UnityServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => locator);

            return container;
        }
Exemplo n.º 24
0
        private void ConfigureUnity()
        {
            Container = new UnityContainer();
            Container.LoadConfiguration();
            UnityServiceLocator locator = new UnityServiceLocator(Container);

            ServiceLocator.SetLocatorProvider(() => locator);

            ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(Container));
        }
Exemplo n.º 25
0
        public static IUnityContainer CreateAndRegisterUnityContainer()
        {
            IUnityContainer unityContainer = new UnityContainer();

            UnityServiceLocator serviceLocator = new UnityServiceLocator(unityContainer);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            return unityContainer;
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
 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;
 }
Exemplo n.º 28
0
        /// <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();
        }
Exemplo n.º 29
0
        /// <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);
        }
Exemplo n.º 30
0
        public static IUnityContainer Compose()
        {
            var container = new UnityContainer()
                .AddNewExtension<ApplicationInitializer>()
                .AddNewExtension<CoreInitializer>()
				.AddNewExtension<ServicesInitializer>();
			
			UnityServiceLocator locator = new UnityServiceLocator(container);
			ServiceLocator.SetLocatorProvider(() => locator);
            return container;
        }
Exemplo n.º 31
0
 private void SetIoc()
 {
     Microsoft.Practices.Unity.UnityServiceLocator locator = new Microsoft.Practices.Unity.UnityServiceLocator(ConfigureUnityContainer());
     ServiceLocator.SetLocatorProvider(() => locator);
 }