Beispiel #1
0
        public void InjectionConstructorThrowsIfNoMatchingConstructor()
        {
            InjectionConstructor ctor = new InjectionConstructor(typeof(double));
            var context = new MockBuilderContext();

            ctor.AddPolicies(typeof(GuineaPig), context.PersistentPolicies);
        }
        /// <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 connectionStringParameter = new InjectionConstructor(ConfigurationManager.ConnectionStrings["db"].ConnectionString);

            container.RegisterType(typeof(IRepository <>), typeof(SqlRepository <>), connectionStringParameter);
            container.RegisterType <IRepository <Person>, PersonRepository>(connectionStringParameter);
        }
Beispiel #3
0
        public void InjectionConstructorInsertsChooserForConstructorWithParameters()
        {
            string expectedString = "Hello";
            int    expectedInt    = 12;

            var ctor    = new InjectionConstructor(expectedString, expectedInt);
            var context = new MockBuilderContext
            {
                BuildKey = new NamedTypeBuildKey(typeof(GuineaPig))
            };
            IPolicyList policies = context.PersistentPolicies;

            ctor.AddPolicies(typeof(GuineaPig), policies);

            var selector = policies.Get <IConstructorSelectorPolicy>(
                new NamedTypeBuildKey(typeof(GuineaPig)));

            SelectedConstructor selected = selector.SelectConstructor(context, policies);

            string[] keys = selected.GetParameterKeys();

            Assert.AreEqual(typeof(GuineaPig).GetConstructor(Sequence.Collect(typeof(string), typeof(int))), selected.Constructor);
            Assert.AreEqual(2, keys.Length);

            Assert.AreEqual(expectedString, (string)ResolveValue(policies, keys[0]));
            Assert.AreEqual(expectedInt, (int)ResolveValue(policies, keys[1]));
        }
Beispiel #4
0
        public static void RegisterComponents()
        {
            var container = new UnityContainer();

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            InjectionConstructor accountInjectionConstructor =
                new InjectionConstructor(new ApplicationDbContext());

            container.RegisterType <AccountController>();
            container.RegisterType <IController, Controller>();

            container.RegisterType
            <IUserStore <ApplicationUser>, UserStore <ApplicationUser> >
                (accountInjectionConstructor);

            container.RegisterType(typeof(IMobiService <>), typeof(MobiService <>));
            container.RegisterType <IProductServices, ProducService>();
            container.RegisterType <IProducsCategoryService, ProducsCategoryService>();
            container.RegisterType <IUOMService, UOMService>();
            container.RegisterType <IPartnerService, PartnerService>();
            container.RegisterType(typeof(IMobiRepository <>), typeof(MobiRepository <>));
            container.RegisterType <ISalesOrderLineService, SalesOrderLineService>();

            container.RegisterType <ISalesService, SaleService>();

            //   container.RegisterType<MobiERPDbContext, ApplicationDbContext>(new HierarchicalLifetimeManager());
            container.RegisterType <UserManager <ApplicationUser> >(new HierarchicalLifetimeManager());
            container.RegisterType <IUserStore <ApplicationUser>, UserStore <ApplicationUser> >(new HierarchicalLifetimeManager());
            container.RegisterType <AccountController>(new InjectionConstructor());

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
        private void RegisterServices(IUnityContainer container)
        {
            _container.RegisterType <IHorsifyDialogService, HorsifyDialogService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <ISongDataProvider, SongDataProvider>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IQueuedSongDataProvider, QueuedSongDataProvider>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IPlaylistService, HorsifyPlaylistService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IDjHorsifyService, DjHorsifyService>(new ContainerControlledLifetimeManager());
            _container.RegisterType <ISongPlayingInfo, SongPlayingInfo>(new ContainerControlledLifetimeManager());
            _container.RegisterType <IVoiceControl, VoiceControl>(new ContainerControlledLifetimeManager());
            try
            {
                //TODO: Get vlc path and options
                //true runs two Vlc instances
                InjectionConstructor ic = new InjectionConstructor("", false);
                _container.RegisterType <IHorsifyMediaController, HorsifyVlcMediaController>("", new ContainerControlledLifetimeManager(), ic);

                InjectionConstructor discordClientCtor = new InjectionConstructor("523161926025609233");
                _container.RegisterType <IDiscordRpcService, DiscordRpcService>(new ContainerControlledLifetimeManager(), discordClientCtor);
            }
            catch (System.Exception ex)
            {
                System.Windows.MessageBox.Show("Couldn't initialize VLC.");
                throw ex;
            }
        }
Beispiel #6
0
        public void InjectionConstructorSetsResolverForInterfaceToLookupInContainer()
        {
            InjectionConstructor  ctor    = new InjectionConstructor("Logger", typeof(ILogger));
            TestingBuilderContext context = new TestingBuilderContext();

            context.BuildKey = typeof(GuineaPig);
            IPolicyList policies = context.PersistentPolicies;

            ctor.AddPolicies(typeof(GuineaPig), policies);

            IConstructorSelectorPolicy selector = policies.Get <IConstructorSelectorPolicy>(
                new NamedTypeBuildKey(typeof(GuineaPig)));

            SelectedConstructor selected = selector.SelectConstructor(context);

            string[] keys = selected.GetParameterKeys();

            Assert.AreEqual(typeof(GuineaPig).GetConstructor(Sequence.Collect(typeof(string), typeof(ILogger))), selected.Constructor);
            Assert.AreEqual(2, keys.Length);

            IDependencyResolverPolicy policy =
                context.Policies.Get <IDependencyResolverPolicy>(keys[1]);

            Assert.IsTrue(policy is NamedTypeDependencyResolverPolicy);
        }
        public static IUnityContainer InitializeContainer(this IUnityContainer container)
        {
            container.RegisterType <IDatabaseConnectionService, DatabaseConnectionServiceFake>(new ContainerControlledLifetimeManager());
            container.RegisterType <IDataAccessService, DataAccessService>(new ContainerControlledLifetimeManager());

            container.RegisterType <IKeychainService, KeychainServiceFake>(new ContainerControlledLifetimeManager());
            container.RegisterType <ILoggerFacade, EmptyLogger>();

            container.RegisterType <IAuthenticationApiWrapper, FakeAuthenticationApiWrapper>(new ContainerControlledLifetimeManager());
            container.RegisterType <ILogApiWrapper, FakeLogApiWrapper>(new ContainerControlledLifetimeManager());
            container.RegisterType <IAuthenticationHelperWrapper, FakeAuthenticationHelperWrapper>(new ContainerControlledLifetimeManager());
            container.RegisterType <IAccountApiWrapper, FakeAccountApiWrapper>(new ContainerControlledLifetimeManager());
            container.RegisterType <IPropertyApiWrapper, FakePropertyApiWrapper>(new ContainerControlledLifetimeManager());
            container.RegisterType <IStoryApiWrapper, FakeStoryApiWrapper>(new ContainerControlledLifetimeManager());

            container.RegisterType <IStoryFacade, StoryFacade>();
            container.RegisterType <IAccountFacade, AccountFacade>();
            container.RegisterType <IPropertyFacade, PropertyFacade>();
            container.RegisterType <ISettingsFacade, SettingsFacade>();
            container.RegisterType <IAuthenticationFacade, AuthenticationFacade>();

            container.RegisterType <IApplicationProvider, ApplicationProviderMock>();

            var para = new InjectionConstructor("OK", container.Resolve <IApplicationProvider>());

            container.RegisterType <IPageDialogService, PageDialogServiceMock>(para);
            container.RegisterType <INavigationService, NavigationServiceMock>();

            return(container);
        }
Beispiel #8
0
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            Container.RegisterType <IApplicationCommands, ApplicationCommandsProxy>();
            Container.RegisterType <IDialogCoordinator, DialogCoordinator>();

            Container.RegisterInstance <ISettingsHypermint>(Container.Resolve <SettingsRepo>());
            Container.RegisterInstance <IFlyoutService>(Container.Resolve <FlyoutService>());
            Container.RegisterInstance <IFileDialogHelper>(Container.Resolve <FileDialogHelper>());
            Container.RegisterInstance <ISelectedService>(Container.Resolve <SelectedService>());
            Container.RegisterInstance <IGameLaunch>(Container.Resolve <GameLaunch>());
            Container.RegisterInstance <IRlScan>(Container.Resolve <RlScan>());

            Container.RegisterType <IImageEditService, ImageEditor>(new ContainerControlledLifetimeManager());
            Container.RegisterType <IPdfService, PdfService>(new ContainerControlledLifetimeManager());
            Container.RegisterType <ISearchYoutube, SearchYoutubeService>(new ContainerControlledLifetimeManager());

            var trashParam = new InjectionConstructor(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Hypermint", "Trash"));

            Container.RegisterType <ITrashMaster, TrashMaster>(new ContainerControlledLifetimeManager(), trashParam);

            //New providers
            Container.RegisterType <IHyperspinManager, HyperspinManager>(new ContainerControlledLifetimeManager());
            Container.RegisterType <IHyperspinXmlDataProvider, HyperspinDataProvider>(new ContainerControlledLifetimeManager());
            Container.RegisterType <IRocketLaunchStatProvider, RocketLaunchStatProvider>(new ContainerControlledLifetimeManager());

            RegisterNavigationTypes();
        }
        public void InjectionConstructorInsertsChooserForConstructorWithParameters()
        {
            string expectedString = "Hello";
            int expectedInt = 12;

            var ctor = new InjectionConstructor(expectedString, expectedInt);
            var context = new MockBuilderContext
                {
                    BuildKey = new NamedTypeBuildKey(typeof (GuineaPig))
                };
            IPolicyList policies = context.PersistentPolicies;

            ctor.AddPolicies(typeof(GuineaPig), policies);

            var selector = policies.Get<IConstructorSelectorPolicy>(
                new NamedTypeBuildKey(typeof(GuineaPig)));

            SelectedConstructor selected = selector.SelectConstructor(context, policies);
            string[] keys = selected.GetParameterKeys();

            Assert.AreEqual(typeof(GuineaPig).GetConstructor(Sequence.Collect(typeof(string), typeof(int))), selected.Constructor);
            Assert.AreEqual(2, keys.Length);

            Assert.AreEqual(expectedString, (string)ResolveValue(policies, keys[0]));
            Assert.AreEqual(expectedInt, (int)ResolveValue(policies, keys[1]));
        }
Beispiel #10
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (var container = new Unity.UnityContainer().EnableDiagnostic())
            {
                string connectionInfo = @"Data Source=12.11.10.1\DATA;Initial Catalog=DATA;User ID=Data;Password=Data;Application Name=UI.NET";
                string userName       = "******";

                container.RegisterType <IConfig, Config>(new InjectionProperty("ConnectionInfo", connectionInfo), new InjectionProperty("UserName", userName));

                //  -- DataAccess -
                container.RegisterType <IDataAccess, DataAccess.DataAccess>();
                //

                //  -- DataStore:
                container.RegisterType <IDataStore, DataStoreManagemer>();
                //

                //
                container.RegisterType <IViewContainer, UserInfoViewContainer>();
                //
                container.RegisterType <IView, formUserInfo>(new InjectionConstructor(typeof(UserInfoViewContainer)));

                //
                var ctorMainPresentation = new InjectionConstructor(typeof(formUserInfo));
                container.RegisterType <IPresentation, MainPresentation>(ctorMainPresentation);
                var obj = container.Resolve <MainPresentation>();
                obj.Populate().GetAwaiter().GetResult();
                obj.Show();
            }
        }
Beispiel #11
0
        public static void Configure(Microsoft.Practices.Unity.IUnityContainer container)
        {
            if (QMailer.GlobalConfiguration.Configuration.DependencyResolver == null)
            {
                QMailer.GlobalConfiguration.Configuration.DependencyResolver = new QMailer.UnityDependencyResolver(container);
            }

            var emailEngines = new ViewEngineCollection()
            {
                new EmailerViewEngine()
            };
            var ic = new InjectionConstructor(emailEngines,
                                              GlobalConfiguration.Configuration.FullUrl ?? "http://localhost",
                                              GlobalConfiguration.Configuration.VirtualPath);

            container.RegisterType <IEmailViewRenderer, EmailViewRenderer>("default", new ContainerControlledLifetimeManager(), ic);

            container.RegisterType <IEmailTemplateService, EmailTemplateService>(new ContainerControlledLifetimeManager());
            container.RegisterType <ICacheService, SimpleCacheService>(new ContainerControlledLifetimeManager());

            if (!container.IsRegistered <QMailer.Web.IModelResolver>())
            {
                container.RegisterType <IModelResolver, DefaultModelResolver>(new ContainerControlledLifetimeManager());
            }
        }
Beispiel #12
0
        private void RegisterDataPersistence()
        {
            var PlayerRepositoryParams = new InjectionConstructor(ConnectionProvider.GetConnection());

            _container.RegisterType <IPlayerRepository, PlayerRepository>(PlayerRepositoryParams);
            _container.RegisterType <IPlayerInBattleRepository, PlayerInBattleRepository>();
        }
Beispiel #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)
        {
            // NOTE: To load from web.config uncomment the line below.
            // Make sure to add a Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your type's mappings here.
            // container.RegisterType<IProductRepository, ProductRepository>();

            container.RegisterType <ExpenseController>();
            container.RegisterType <UserController>();
            container.RegisterType <GroupsController>();

            container.RegisterType <IDbFactory, DbFactory>();

            var factoryInjection = new InjectionConstructor(container.Resolve <IDbFactory>());

            container.RegisterType <IUnitOfWork, UnitOfWork>(factoryInjection);
            var unitOfWorkInjection = new InjectionConstructor(container.Resolve <IUnitOfWork>());

            container.RegisterType <IExpenseRepository, ExpenseRepository>(factoryInjection);
            container.RegisterType <IValidator <Expense>, ExpenseValidator>();
            container.RegisterType <IExpenseService, ExpenseService>(new InjectionConstructor(new object[] { container.Resolve <IExpenseRepository>(), container.Resolve <IUnitOfWork>(), container.Resolve <IValidator <Expense> >() }));

            container.RegisterType <IUserRepository, UserRepository>(factoryInjection);
            container.RegisterType <IValidator <User>, UserValidator>();
            container.RegisterType <IUserService, UserService>(new InjectionConstructor(new object[] { container.Resolve <IUserRepository>(), container.Resolve <IUnitOfWork>(), container.Resolve <IValidator <User> >() }));

            container.RegisterType <IGroupRepository, GroupRepository>(factoryInjection);
            container.RegisterType <IValidator <Group>, GroupValidator>();
            container.RegisterType <IGroupService, GroupService>(new InjectionConstructor(new object[] { container.Resolve <IGroupRepository>(), container.Resolve <IUnitOfWork>(), container.Resolve <IValidator <Group> >() }));
        }
Beispiel #14
0
        public void RegisterType <TFrom, TTo>(string pAliais, bool pUsaParametros, bool pSingleton = false, bool pInjetaContainer = true, params object[] parameterValues) where TTo : TFrom
        {
            var lParameter = new List <InjectionParameter>();

            if (pUsaParametros)
            {
                lParameter.AddRange(from param in parameterValues let type = param.GetType() select new InjectionParameter(type, param));
            }

            if (pInjetaContainer)
            {
                lParameter.Add(new InjectionParameter(this));
            }

            var injectionConstructor =
                new InjectionConstructor(lParameter.ToArray());

            if (pSingleton)
            {
                _container.RegisterType <TFrom, TTo>(pAliais, new PerThreadLifetimeManager(), injectionConstructor);
            }
            else
            {
                _container.RegisterType <TFrom, TTo>(pAliais, injectionConstructor);
            }
        }
        protected override void Initialize()
        {
            var constructor = new InjectionConstructor(new UnityJobFactory(Container), new InjectionParameter <NameValueCollection>(quartzProperties));

            this.Container.RegisterType <ISchedulerFactory, UnitySchedulerFactory>(new ContainerControlledLifetimeManager(), constructor);

            this.Container.RegisterFactory <IScheduler>(c => c.Resolve <ISchedulerFactory>().GetScheduler().Result);
        }
Beispiel #16
0
        // https://github.com/unitycontainer/abstractions/issues/96
        public override void Issue_Abstractions_96()
        {
            // Act
            var ctor = new InjectionConstructor();

            Container.RegisterType <IService, Service>(ctor);
            Container.RegisterType <IService, Service>("name", ctor);
        }
        public void InjectionConstructorThrowsIfNoMatchingConstructor()
        {
            InjectionConstructor ctor = new InjectionConstructor(typeof(double));
            var context = new MockBuilderContext();

            AssertExtensions.AssertException <InvalidOperationException>(
                () => ctor.AddPolicies(typeof(GuineaPig), context.PersistentPolicies));
        }
Beispiel #18
0
        protected override void Initialize()
        {
            Container.RegisterInstance(new Context(), new PerResolveLifetimeManager());

            var accountInjectionConstructor = new InjectionConstructor(new ResolvedParameter <Context>());

            Container.RegisterType <IUserStore <AuthUser>, UserStore <AuthUser> >(accountInjectionConstructor);
            Container.RegisterType <AppUserManager>();
        }
Beispiel #19
0
        private static void RegisterEarthOnlineEntities(IUnityContainer container)
        {
            var earthSettings = ConfigReader <string> .GetSetting("EarthOnlineEntities") ?? string.Empty;

            var manager     = new PerRequestLifetimeManager();
            var constructor = new InjectionConstructor(earthSettings);

            container.RegisterType <EarthOnlineEntities>(manager, constructor);
        }
Beispiel #20
0
        public static UnityContainer InitUnityContainer()
        {
            var container  = new UnityContainer();
            var serializer = new JsonSerializer();

            container.RegisterInstance <ISerializer>(serializer);
            container.RegisterInstance <IMetadataProvider>(new StandardMetadataProvider());

            //container.RegisterType<IMessageSender, MessageSender>(
            //    "Commands",
            //    new TransientLifetimeManager(),
            //    new InjectionConstructor("SqlBus", "SqlBus.Commands")
            //);

            container.RegisterType <IMessageSender, MessageSender>(
                "Events",
                new TransientLifetimeManager(),
                new InjectionConstructor("SqlBus", "SqlBus.Events")
                );

            //container.RegisterType<ICommandBus, CommandBus>(
            //    new ContainerControlledLifetimeManager(),
            //    new InjectionConstructor(new ResolvedParameter<IMessageSender>("Commands"), serializer)
            //);


            container.RegisterType <IEventBus, EventBus>(
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor(new ResolvedParameter <IMessageSender>("Events"), typeof(ISerializer))
                );

            container.RegisterType <IConferenceRepositoryContext, ConferenceRepositoryContext>();
            container.RegisterType <IConferenceRepository, ConferenceRepository>(
                new TransientLifetimeManager(),
                new InjectionConstructor(typeof(IConferenceRepositoryContext)));

            container.RegisterType <IOrderRepository, OrderRepository>(
                new TransientLifetimeManager(),
                new InjectionConstructor(typeof(IConferenceRepositoryContext)));
            container.RegisterType <ISeatTypeRepository, SeatTypeRepository>(
                new TransientLifetimeManager(),
                new InjectionConstructor(typeof(IConferenceRepositoryContext)));

            var injectionConstructor = new InjectionConstructor(
                typeof(IEventBus),
                typeof(IConferenceRepositoryContext),
                typeof(IConferenceRepository),
                typeof(IOrderRepository),
                typeof(ISeatTypeRepository)
                );

            container.RegisterType <IConferenceService, ConferenceService>(
                new TransientLifetimeManager(),
                injectionConstructor);

            return(container);
        }
        public static void RegisterType <TFrom, TTo>(InjectionConstructor injectionConstructor) where TTo : TFrom
        {
            lock (UnityContainer)
            {
                UnityContainer.RegisterType <TFrom, TTo>(new ContainerControlledLifetimeManager(), injectionConstructor);
            }

            CheckReleaseLatch(typeof(TFrom));
        }
Beispiel #22
0
        /// <summary>
        /// Registers the specified type to be resolved with the specified concrete type, specifying
        /// a name and the parameters through a anonymous object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public IDependencyInjectionContainer Register <T>(string name, object parameters) where T : class
        {
            object[]             parametersArray      = this.GetParameters(parameters).ToArray();
            InjectionConstructor injectionConstructor = new InjectionConstructor(parametersArray);

            this.unityContainer.RegisterType <T>(name, injectionConstructor);

            return(this);
        }
Beispiel #23
0
        private void RegisterQueryableRepository <TEntity>() where TEntity : class, IQueryableAggregateRoot
        {
            _container.RegisterType <IQuery <TEntity>, EntityFrameworkCodeFirstQueryable <TEntity> >();
            var context = _container.Resolve <EFTestContext>();
            var query   = _container.Resolve <IQuery <TEntity> >(new ParameterOverride("dbContext", context));
            var injectionConstructor = new InjectionConstructor(query);

            _container.RegisterType <IQueryableRepository <TEntity>, QueryableRepository <TEntity> >(injectionConstructor);
        }
Beispiel #24
0
        //The solution to handle multiple overloaded constructors using unity is available at
        // http://stackoverflow.com/questions/4059991/microsoft-unity-how-to-specify-a-certain-parameter-in-constructor

        private void RegisterCommandRepository <TEntity>(bool isUnitOfWorkRequired = false) where TEntity : BaseEntity <int>, ICommandAggregateRoot
        {
            _container.RegisterType <ICommand <TEntity>, EntityFrameworkCodeFirstCommand <TEntity, int> >();
            EFTestContext        context              = _container.Resolve <EFTestContext>();
            ICommand <TEntity>   command              = _container.Resolve <ICommand <TEntity> >(new ParameterOverride("dbContext", context));
            string               respositoryName      = isUnitOfWorkRequired ? REPOSITORY_WITH_UNIT_OF_WORK : REPOSITORY_WITHOUT_UNIT_OF_WORK;
            InjectionConstructor injectionConstructor = !isUnitOfWorkRequired ? new InjectionConstructor(command) : new InjectionConstructor(typeof(IUnitOfWork), command);

            _container.RegisterType <ICommandRepository <TEntity>, CommandRepository <TEntity> >(respositoryName, injectionConstructor);
        }
        protected override void RegisterCommandService <TEntity>()
        {
            var name = typeof(TEntity).Name + SERVICE_SUFFIX;

            _container.RegisterType <ICommand <TEntity>, TestServiceCommand <TEntity> >(name);
            var command = _container.Resolve <ICommand <TEntity> >(name);
            var injectionConstructor = new InjectionConstructor(command);

            _container.RegisterType <ICommandRepository <TEntity>, CommandRepository <TEntity> >(name, injectionConstructor);
        }
Beispiel #26
0
        /// <summary>
        /// Registers first collection
        /// </summary>
        private static void RegisterFirstCollection(ISolrCloudStateProvider cloudStateProvider, IUnityContainer container)
        {
            var injection = new InjectionConstructor(
                new ResolvedParameter <ISolrCloudStateProvider>(cloudStateProvider.Key),
                new ResolvedParameter <ISolrOperationsProvider>());

            container.RegisterType(typeof(ISolrBasicOperations <>), typeof(SolrCloudBasicOperations <>), injection);
            container.RegisterType(typeof(ISolrBasicReadOnlyOperations <>), typeof(SolrCloudBasicOperations <>), injection);
            container.RegisterType(typeof(ISolrOperations <>), typeof(SolrCloudOperations <>), injection);
            container.RegisterType(typeof(ISolrReadOnlyOperations <>), typeof(SolrCloudOperations <>), injection);
        }
Beispiel #27
0
        private static void RegisterRepositories(IUnityContainer container)
        {
            var connectionString  = ConfigurationHelper.GetPicturraConnectionString();
            var connectionFactory = new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider);

            var connectionFactoryConstructor = new InjectionConstructor(connectionFactory);

            container.RegisterType <IContactRepository, ContactRepository>(connectionFactoryConstructor);

            ConfigureDb(connectionFactory);
        }
Beispiel #28
0
        protected override void RegisterDepartmentCommandService()
        {
            var name = typeof(Department).Name + SERVICE_SUFFIX;

            _container.RegisterType <ICommand <Department>, DepartmentTestServiceCommand>(name, new InjectionConstructor(_connection));
            var context = _container.Resolve <EFTestContext>();
            var command = _container.Resolve <ICommand <Department> >(name, new ParameterOverride("dbContext", context));
            var injectionConstructor = new InjectionConstructor(typeof(IUnitOfWork), command);

            _container.RegisterType <ICommandRepository <Department>, CommandRepository <Department> >(name, injectionConstructor);
        }
Beispiel #29
0
        public WheelModuleInit(IUnityContainer container, IRegionManager manager) : base(container, manager)
        {
            //Initiate the ItextImageService with ProgramData Preset path
            SettingsRepo settings   = (SettingsRepo)container.Resolve(typeof(SettingsRepo));
            var          ctorParams = new InjectionConstructor(settings.HypermintSettings.PresetPath);

            container.RegisterType <ITextImageService, TextImage>(new ContainerControlledLifetimeManager(), ctorParams);

            manager.RegisterViewWithRegion(RegionNames.FilesRegion, typeof(WheelProcessView));
            manager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(SimpleWheelView));
        }
Beispiel #30
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)
        {
            // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
            // container.LoadConfiguration();

            // TODO: Register your types here
            // container.RegisterType<IProductRepository, ProductRepository>();
            var injector = new InjectionConstructor(TimeSpan.FromSeconds(3));

            container.RegisterType <IFiveNumbers, FiveNumbers>(new ContainerControlledLifetimeManager(), injector);
        }
 public void Register <TFrom, TTo>(LifetimeManager lifetimeMgr, InjectionConstructor ictor, string name = null)
 {
     if (name != null)
     {
         _container.RegisterType(typeof(TFrom), typeof(TTo), name, lifetimeMgr, ictor);
     }
     else
     {
         _container.RegisterType(typeof(TFrom), typeof(TTo), lifetimeMgr, ictor);
     }
 }
        public void InjectionConstructorInsertsChooserForDefaultConstructor()
        {
            var ctor = new InjectionConstructor();
            var context = new MockBuilderContext
                {
                    BuildKey = new NamedTypeBuildKey(typeof (GuineaPig))
                };
            IPolicyList policies = context.PersistentPolicies;

            ctor.AddPolicies(typeof(GuineaPig), policies);

            var selector = policies.Get<IConstructorSelectorPolicy>(
                new NamedTypeBuildKey(typeof(GuineaPig)));

            SelectedConstructor selected = selector.SelectConstructor(context, policies);
            Assert.AreEqual(typeof(GuineaPig).GetConstructor(new Type[0]), selected.Constructor);
            Assert.AreEqual(0, selected.GetParameterKeys().Length);
        }
        public void InjectionConstructorSetsResolverForInterfaceToLookupInContainer()
        {
            var ctor = new InjectionConstructor("Logger", typeof(ILogger));
            var context = new MockBuilderContext();
            context.BuildKey = new NamedTypeBuildKey(typeof(GuineaPig));
            IPolicyList policies = context.PersistentPolicies;

            ctor.AddPolicies(typeof(GuineaPig), policies);

            var selector = policies.Get<IConstructorSelectorPolicy>(
                new NamedTypeBuildKey(typeof(GuineaPig)));

            SelectedConstructor selected = selector.SelectConstructor(context, policies);
            string[] keys = selected.GetParameterKeys();

            Assert.AreEqual(typeof(GuineaPig).GetConstructor(Sequence.Collect(typeof(string), typeof(ILogger))), selected.Constructor);
            Assert.AreEqual(2, keys.Length);

            var policy = context.Policies.Get<IDependencyResolverPolicy>(keys[1]);
            Assert.IsTrue(policy is NamedTypeDependencyResolverPolicy);
        }
        public void InjectionConstructorThrowsIfNoMatchingConstructor()
        {
            InjectionConstructor ctor = new InjectionConstructor(typeof(double));
            var context = new MockBuilderContext();

            AssertExtensions.AssertException<InvalidOperationException>(
                () => ctor.AddPolicies(typeof(GuineaPig), context.PersistentPolicies));
        }
        public void InjectionConstructorThrowsIfNoMatchingConstructor()
        {
            InjectionConstructor ctor = new InjectionConstructor(typeof(double));
            var context = new MockBuilderContext();

            ctor.AddPolicies(typeof(GuineaPig), context.PersistentPolicies);
        }