Ejemplo n.º 1
0
 private IUnityContainer InitializeContainer()
 {
     InjectionConstructor ctor = new InjectionConstructor(ConfigurationManager.ConnectionStrings["todo"].ConnectionString);
     UnityContainer container = new UnityContainer()
     container.RegisterType<ITodoRepository, TodosRepository>(ctor);
     return container;
 }
Ejemplo n.º 2
0
        public static void RegisterComponents(HttpConfiguration config)
        {
            var container = new UnityContainer();

            var configuration = Core.Configuration.MetroApiConfig.GetConfig();
            var citiesConfig = configuration.Cities
                .OfType<Core.Configuration.City>()
                .ToDictionary(x => x.Id, x =>
                {
                    if (Path.IsPathRooted(x.Filepath))
                    {
                        return x.Filepath;
                    }
                    else
                    {
                        return HostingEnvironment.MapPath(x.Filepath);
                    }
                });

            var citiesDictionary = new InjectionConstructor(
                new InjectionParameter<IDictionary<string, string>>(citiesConfig));

            container.RegisterType<IMetroService, XmlMetroService>(citiesDictionary);

            config.DependencyResolver = new UnityDependencyResolver(container);
        }
Ejemplo n.º 3
0
 private static void RegisterTypes(IUnityContainer container)
 {
     var injectedContext = new InjectionConstructor(new ExpenseSystemEntities());
     container.RegisterType<IExpenseRecordRepository, ExpenseRecordRepository>(injectedContext);
     container.RegisterType<ITagRepository, TagRepository>(injectedContext);
     container.RegisterType<IUserRepository, UserRepository>(injectedContext);
 }
Ejemplo n.º 4
0
 private static void RegisterIDbConnectionFactory(IUnityContainer container)
 {
     ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["DefaultConnection"];
     string connectionString = setting.ConnectionString;
     var injection = new InjectionConstructor(connectionString);
     container.RegisterType<IAsyncDbConnectionFactory, SqlConnectionFactory>(injection);
 }
Ejemplo n.º 5
0
        public static void ConfigureUnityContainer(IUnityContainer container)
        {
            //Registrations
            #region Repository
            container.RegisterType<NHibernateSessionFactory, SessionFactory>
                                    (new ContainerControlledLifetimeManager());
            var factory = container.Resolve<SessionFactory>();
            var injectedFactory = new InjectionConstructor(factory);
            container.RegisterType<IRepository, NHibernateRepository>
                                    (new ContextLifetimeManager<IRepository>(), injectedFactory);
            #endregion

            #region Facebook
            var fbSettings = ConfigurationManager.GetSection("facebookSettings") as FacebookConfigurationSection;
            var injectedFBSettings = new InjectionConstructor(fbSettings.AppId,fbSettings.AppSecret);
            container.RegisterType<FacebookClient, FacebookWebClient>(injectedFBSettings);
            #endregion

            #region Logger

            container.RegisterType<Log4NetFactory, LogFactory>
                                    (new ContainerControlledLifetimeManager());
            var logFactory = container.Resolve<LogFactory>();

            var injectedLogFactory = new InjectionConstructor(logFactory);
            container.RegisterType<ILogger, Log4Net>
                                    (new ContainerControlledLifetimeManager(),injectedLogFactory);
            #endregion
        }
        /// <summary>
        /// Initial the container with this extension's functionality.
        /// </summary>
        /// <remarks>
        /// When overridden in a derived class, this method will modify the given
        ///             <see cref="T:Microsoft.Practices.Unity.ExtensionContext"/> by adding strategies, policies, etc. to
        ///             install it's functions into the container.
        /// </remarks>
        protected override void Initialize()
        {
            Injection.Engine.RegisterType<IMsBuilderificCoreOptions, MsBuilderificCoreOptions>();

            var injectedBuilders = new InjectionConstructor(Injection.Engine.ResolveAll<IBuildOrderVisitor>());
            Injection.Engine.RegisterType<IMsBuildFileCore, MsBuildFileCore>(injectedBuilders);

            injectedBuilders = new InjectionConstructor(Injection.Engine.ResolveAll<IVisualStudioProjectLoader>());
            Injection.Engine.RegisterType<IProjectDependencyFinder, ProjectDependencyFinder>(injectedBuilders);
        }
 protected override void InitializeShell()
 {
     base.InitializeShell();
     Container.RegisterType<IMessenger, Messenger>(new ContainerControlledLifetimeManager());
     Container.RegisterInstance(CommonLib.IssueRepository.Current);
     var clientConst = new InjectionConstructor(new System.ServiceModel.InstanceContext(CommonLib.IssueRepository.Current));
     Container.RegisterType<CommonLib.AwesomeService.IGeoDataService, CommonLib.AwesomeService.GeoDataServiceClient>(new ContainerControlledLifetimeManager(), clientConst);
     App.Current.MainWindow = (Window)Shell;
     App.Current.MainWindow.Show();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates an instance of UnityContainer and registers the instances which needs to be injected
        /// to Controllers/Views/Services, etc.
        /// </summary>
        private static void RegisterUnityContainer()
        {
            _container = new UnityContainer();
            var earthSettings = ConfigReader<string>.GetSetting("EarthOnlineEntities");
            var manager = new PerRequestLifetimeManager();
            var constructor = new InjectionConstructor(earthSettings);
            _container.RegisterType<EarthOnlineEntities>(manager,constructor);

            RegisterRepositories(_container);
            RegisterServices(_container);

            DependencyResolver.SetResolver(new UnityDependencyResolver(_container));
        }
Ejemplo n.º 9
0
        /// <summary>Use Log4Net as the logger for the enode framework.
        /// </summary>
        /// <returns></returns>
        public static Configuration RegisterMessageContextType(this Configuration configuration, Type messageContextType, InjectionConstructor injectionConstructor = null)
        {
            if (injectionConstructor == null)
            {
                injectionConstructor = new InjectionConstructor(new ResolvedParameter(typeof(IMessage), "message"));
            }
            IoCFactory.Instance.CurrentContainer
                               .RegisterType(typeof(IMessageContext),
                                             messageContextType,
                                             "MessageStoreMapping",
                                             injectionConstructor);

            return configuration;
        }
Ejemplo n.º 10
0
        public static void Register(HttpConfiguration config)
        {
            var dbContext = new ExampleDbContext();
            var container = new UnityContainer();

            container.RegisterType<IRdfWriter, RdfXmlWriter>(new InjectionConstructor());

            container.RegisterType<ISelpConfiguration, InMemoryConfiguration>();
            var efConstructorParameter = new InjectionConstructor(dbContext, container.Resolve<ISelpConfiguration>());

            container.RegisterType<IUserRepository, UserRepository>(efConstructorParameter);
            container.RegisterType<IRegionRepository, RegionRepository>(efConstructorParameter);
            container.RegisterType<IPolicyRepository, PolicyRepository>(efConstructorParameter);
            container.RegisterType<IPartyRepository, PartyRepository>(efConstructorParameter);
            config.DependencyResolver = new UnityResolver(container);
        }
Ejemplo n.º 11
0
 private static IUnityContainer InitializeContainer()
 {
     IUnityContainer container = new UnityContainer();
     //container.RegisterType<ITodoRepository, TodosRepository>(injectionConstructor);
     var injectionConstructor = new InjectionConstructor(ConfigurationManager.ConnectionStrings["FDAEntities"].ConnectionString);
     container.RegisterType<FDAEntities>(injectionConstructor)
     .RegisterType<IUmbrellaRepository, UmbrellaRepository>()
     .RegisterType<IReferenceRepository, ReferenceRepository>()
     .RegisterType<IPartyRepository, PartyRepository>()
     .RegisterType<IUmbrellaService, UmbrellaService>()
     .RegisterType<IAuthenticationService, AuthenticationService>()
     .RegisterType <IActiveDirectorySettings, ActiveDirectorySettings>()
     ;
     //new InjectionConstructor(ConfigurationManager.ConnectionStrings["FDAEntities"].ConnectionString);
     return container;
 }
        protected override void Initialize()
        {
            string connectionString =
                ConfigurationManager.ConnectionStrings
                ["CommerceObjectContext"].ConnectionString;
            var sqlCtorParam = new InjectionConstructor(connectionString);

            this.Container.RegisterType<ProductRepository, SqlProductRepository>(new PerResolveLifetimeManager(), sqlCtorParam);
            this.Container.RegisterType<BasketRepository, SqlBasketRepository>(new PerResolveLifetimeManager(), sqlCtorParam);
            this.Container.RegisterType<DiscountRepository, SqlDiscountRepository>(new PerResolveLifetimeManager(), sqlCtorParam);

            this.Container.RegisterType<BasketDiscountPolicy, RepositoryBasketDiscountPolicy>(new PerResolveLifetimeManager());

            this.Container.RegisterType<IBasketService, BasketService>(new PerResolveLifetimeManager());

            this.Container.RegisterType<CurrencyProvider, SqlCurrencyProvider>(new PerResolveLifetimeManager(), sqlCtorParam);

            this.Container.RegisterType<AccountController>(new InjectionConstructor());
        }
Ejemplo n.º 13
0
		/// <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 documentClient = new DocumentClient( new Uri( ConfigurationManager.AppSettings.Get( "DocumentDB:Uri" ) ) ,
													 ConfigurationManager.AppSettings.Get( "DocumentDB:Key" ) );

			var dataCollectionConstructor = new InjectionConstructor( documentClient ,
																	  ConfigurationManager.AppSettings.Get( "DocumentDB:Database" ) ,
																	  true );

			// DocumentDB
			container.RegisterType<IDocumentManager , DocumentManager>( new PerRequestLifetimeManager() ,
																		dataCollectionConstructor );

			container.RegisterType( typeof (IIdentityCollectionManager<>) ,
									typeof (DocumentManager) ,
									new PerRequestLifetimeManager() ,
									dataCollectionConstructor );

			// Username and message service types
			container.RegisterType<SmtpClient>( new InjectionConstructor() );
			container.RegisterType<IEmailService , EmailService>();

			// Http context types
			container.RegisterType<HttpContextBase>( new InjectionFactory( _ => new HttpContextWrapper( HttpContext.Current ) ) );
			container.RegisterType<IOwinContext>( new InjectionFactory( c => c.Resolve<HttpContextBase>().GetOwinContext() ) );
			container.RegisterType<IAuthenticationManager>( new InjectionFactory( c => c.Resolve<IOwinContext>().Authentication ) );

			// Identity types
			container.RegisterType( typeof (ApplicationUser) );
			container.RegisterType<IUserValidator , UserValidator>();
			container.RegisterType<IIdentityRoleStore , ApplicationRoleStore>();
			container.RegisterType<IUserManager , UserManager>( new PerRequestLifetimeManager() );
			container.RegisterType<ISignInManager , SignInManager>( new PerRequestLifetimeManager() );
			container.RegisterType( typeof (IDocumentDBUserStore<>) , typeof (DocumentDBUserStore<>) );

			// Other types
			container.RegisterType<INetscapeBookmarkParser , NetscapeBookmarkParser>();
		}
Ejemplo n.º 14
0
 private static void RegisterSolrOperations(SolrCore core, IUnityContainer container, bool isNamed = true) {
     var ISolrReadOnlyOperations = typeof (ISolrReadOnlyOperations<>).MakeGenericType(core.DocumentType);
     var ISolrBasicOperations = typeof (ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
     var ISolrOperations = typeof (ISolrOperations<>).MakeGenericType(core.DocumentType);
     var SolrServer = typeof (SolrServer<>).MakeGenericType(core.DocumentType);
     var registrationId = isNamed ? core.Id : null;
     var injectionConstructor = new InjectionConstructor(
         new ResolvedParameter(ISolrBasicOperations, registrationId),
         new ResolvedParameter(typeof (IReadOnlyMappingManager)),
         new ResolvedParameter(typeof (IMappingValidator)));
     container.RegisterType(ISolrOperations, SolrServer, registrationId, injectionConstructor);
     container.RegisterType(ISolrReadOnlyOperations, SolrServer, registrationId, injectionConstructor);
 }
Ejemplo n.º 15
0
        private static void RegisterBasicOperations(SolrCore core, IUnityContainer container, bool isNamed = true) {
            var ISolrBasicReadOnlyOperations = typeof (ISolrBasicReadOnlyOperations<>).MakeGenericType(core.DocumentType);
            var SolrBasicServer = typeof (SolrBasicServer<>).MakeGenericType(core.DocumentType);
            var ISolrBasicOperations = typeof (ISolrBasicOperations<>).MakeGenericType(core.DocumentType);
            var ISolrQueryExecuter = typeof (ISolrQueryExecuter<>).MakeGenericType(core.DocumentType);
            var registrationId = isNamed ? core.Id : null;
            string coreConnectionId = GetCoreConnectionId(core.Id);

            var injectionParameters = new InjectionConstructor(
               new ResolvedParameter(typeof(ISolrConnection), coreConnectionId),
               new ResolvedParameter(ISolrQueryExecuter, registrationId),
               new ResolvedParameter(typeof(ISolrDocumentSerializer<>).MakeGenericType(core.DocumentType)),
               new ResolvedParameter(typeof(ISolrSchemaParser)),
               new ResolvedParameter(typeof(ISolrHeaderResponseParser)),
               new ResolvedParameter(typeof(ISolrQuerySerializer)),
               new ResolvedParameter(typeof(ISolrDIHStatusParser)),
               new ResolvedParameter(typeof(ISolrExtractResponseParser)));

            container.RegisterType(ISolrBasicOperations, SolrBasicServer, registrationId, injectionParameters);
            container.RegisterType(ISolrBasicReadOnlyOperations, SolrBasicServer, registrationId, injectionParameters);
        }
 /// <summary>
 /// Instantiates a <see cref="Registration"/>
 /// </summary>
 /// <param name="type"></param>
 /// <param name="mapTo"></param>
 /// <param name="lifetime"></param>
 /// <param name="name"></param>
 /// <param name="injectionConstructor"></param>
 public Registration(Type type,
                     Type mapTo, 
                     LifetimeManager lifetime,
                     string name,
                     InjectionConstructor injectionConstructor = null)
 {
     _type = type;
     _mapTo = mapTo;
     _lifetime = lifetime;
     _name = name;
     _injectionConstructor = injectionConstructor;
 }
 private static void RegisterDataStorageInContainer(UnityContainer unityContainer)
 {
     var injectionConstructor = new InjectionConstructor(new BlogDataContext());
     unityContainer.RegisterType<IDataStorage, DataStorage>(injectionConstructor);
 }
        private static IUnityContainer BuildContainer()
        {
            IUnityContainer container = new UnityContainer();

            string connectionString = ConfigurationManager.ConnectionStrings["UndeadEarthConnectionString"].ConnectionString;
            InjectionConstructor connectionStringConstructor = new InjectionConstructor(connectionString);

            container.RegisterType<IDistanceCalculator, DistanceCalculator>();

            InjectionConstructor zombiePackConstructor =
                new InjectionConstructor(connectionString, typeof(IDistanceCalculator));

            InjectionConstructor storesConstructor =
                new InjectionConstructor(connectionString, typeof(IDistanceCalculator));

            InjectionConstructor safeHouseConstructor =
                new InjectionConstructor(connectionString, typeof(IDistanceCalculator));

            container.RegisterType<IZombiePackRetriever, ZombiePackRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<ZombiePackRepository>(zombiePackConstructor);

            container.RegisterType<IUserRetriever, UserRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<UserRepository>(connectionStringConstructor);

            container.RegisterType<IUserSaver, UserRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<UserRepository>(connectionStringConstructor);

            container.RegisterType<IHotZoneRetriever, HotZoneRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<HotZoneRepository>(connectionStringConstructor);

            container.RegisterType<IUserZombiePackProgressRetriever, UserZombiePackProgressRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<UserZombiePackProgressRepository>(connectionStringConstructor);

            container.RegisterType<IUserZombiePackProgressSaver, UserZombiePackProgressRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<UserZombiePackProgressRepository>(connectionStringConstructor);

            container.RegisterType<IStoreRetriever, StoreRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<StoreRepository>(storesConstructor);

            container.RegisterType<IItemRetriever, ItemRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<ItemRepository>(connectionStringConstructor);

            container.RegisterType<IUserItemRetriever, ItemRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<ItemRepository>(connectionStringConstructor);

            container.RegisterType<IUserItemSaver, ItemRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<ItemRepository>(connectionStringConstructor);

            container.RegisterType<ISafeHouseRetriever, SafeHouseRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<SafeHouseRepository>(safeHouseConstructor);

            container.RegisterType<ISafeHouseItemSaver, ItemRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<ItemRepository>();

            container.RegisterType<IUserCountsSaver, UserCountsRepository>()
                     .Configure<InjectedMembers>()
                     .ConfigureInjectionFor<UserCountsRepository>(connectionStringConstructor);

            container.RegisterType<IUserStatsRetriever, UserCountsRepository>()
                .Configure<InjectedMembers>()
                .ConfigureInjectionFor<UserCountsRepository>(connectionStringConstructor);

            InjectionConstructor zombieCalculatorConstructor =
                new InjectionConstructor(typeof(IUserZombiePackProgressSaver));

            container.RegisterType<IUserEnergyProvider, UserEnergyAndSightProvider>();
            container.RegisterType<IUserMoveDirector, UserMoveDirector>();
            container.RegisterType<IHuntDirector, HuntDirector>();
            container.RegisterType<IShopDirector, ShopDirector>();
            container.RegisterType<ISafeHouseDirector, SafeHouseDirector>();
            container.RegisterType<IUserAttackPowerProvider, UserAttackPowerProvider>();
            container.RegisterType<IZombiePackDifficultyDirector, ZombiePackDifficultyDirector>();
            container.RegisterType<IUserPotentialProvider, UserPotentialProvider>();
            container.RegisterType<IRandomNumberProvider, RandomNumberProvider>();
            container.RegisterType<IUserSightRadiusProvider, UserEnergyAndSightProvider>();
            container.RegisterType<IItemUsageDirector, ItemUsageDirector>();
            container.RegisterType<IUserLevelService, UserLevelService>();
            container.RegisterType<IAchievementProvider, AchievementProvider>();
            container.RegisterType<IUserCreationService, UserCreationService>();

            return container;
        }