コード例 #1
0
        public void ClassWithResolvableAndMultipleContructors_should_pick_contructor_with_most_params()
        {
            var request = new ClassWithIntConstructor(1);

            var factory = new FactoryProvider();

            factory.Register(new HttpRequestContext(request, null));
            factory.Register(new BasicApplicationContext(null, null, null));

            var typeFactory = CreateWithFactory(factory);

            var result = typeFactory.Create(typeof(ClassWithResolvableAndMultipleContructors));

            var newInstance = result as ClassWithResolvableAndMultipleContructors;

            Assert.That(newInstance, Is.Not.Null);

            Assert.That(newInstance.RequestContext, Is.Not.Null);
            Assert.That(newInstance.ApplicationContext, Is.Not.Null);
            Assert.That(newInstance.IntValue, Is.EqualTo(default(int)));

            var resolvedRequest = ((HttpRequestContext)newInstance.RequestContext).Dto as ClassWithIntConstructor;

            Assert.That(resolvedRequest, Is.Not.Null);
            Assert.That(resolvedRequest.IntValue, Is.EqualTo(1));
        }
コード例 #2
0
ファイル: AppHost.cs プロジェクト: fengshao0907/servicestack
        private AppHost()
        {
            LogManager.LogFactory = new Log4NetFactory(true);

            var factory         = new FactoryProvider(FactoryUtils.ObjectFactory, LogManager.LogFactory);
            var providerManager = new Db4oFileProviderManager(Config.ConnectionString);

            var configDb4o = Db4oFactory.Configure();

            configDb4o.ActivationDepth(5);
            configDb4o.UpdateDepth(5);
            configDb4o.OptimizeNativeQueries(true);

            factory.Register(providerManager);             //Keep the manager from disposing providers it created
            factory.Register(providerManager.GetProvider());

            // Create the ApplicationContext injected with the static service implementations
            ApplicationContext.SetInstanceContext(new ApplicationContext {
                Factory   = factory,
                Cache     = new MemoryCacheClient(),
                Resources = new ConfigurationResourceManager(),
            });

            SetConfig(new EndpointHostConfig {
                ServiceName         = Config.ServiceName,
                OperationsNamespace = Config.OperationNamespace,
                ServiceModelFinder  = ServiceModelFinder.Instance,
                ServiceController   = new ServiceController(new ServiceResolver()),
            });
        }
コード例 #3
0
        public void Can_create_ClassWithAResolvableContructors()
        {
            var request = new ClassWithIntConstructor(1);

            var factory = new FactoryProvider();

            factory.Register(new HttpRequestContext(request, null));
            factory.Register(new BasicApplicationContext(null, null, null));

            var typeFactory = CreateWithFactory(factory);

            var result = typeFactory.Create(typeof(ClassWithAResolvableContructors));

            var newInstance = result as ClassWithAResolvableContructors;

            Assert.That(newInstance, Is.Not.Null);

            Assert.That(newInstance.RequestContext, Is.Not.Null);
            Assert.That(newInstance.ApplicationContext, Is.Not.Null);

            var resolvedRequest = ((HttpRequestContext)newInstance.RequestContext).Dto as ClassWithIntConstructor;

            Assert.That(resolvedRequest, Is.Not.Null);
            Assert.That(resolvedRequest.IntValue, Is.EqualTo(1));
        }
コード例 #4
0
ファイル: AppHost.cs プロジェクト: EvgeniyProtas/servicestack
        private AppHost()
        {
            LogManager.LogFactory = new Log4NetFactory(true);

            var factory = new FactoryProvider(FactoryUtils.ObjectFactory, LogManager.LogFactory);
            var providerManager = new Db4oFileProviderManager(Config.ConnectionString);

            var configDb4o = Db4oFactory.Configure();
            configDb4o.ActivationDepth(5);
            configDb4o.UpdateDepth(5);
            configDb4o.OptimizeNativeQueries(true);

            factory.Register(providerManager); //Keep the manager from disposing providers it created
            factory.Register(providerManager.GetProvider());

            // Create the ApplicationContext injected with the static service implementations
            ApplicationContext.SetInstanceContext(new ApplicationContext {
                Factory = factory,
                Cache = new MemoryCacheClient(),
                Resources = new ConfigurationResourceManager(),
            });

            SetConfig(new EndpointHostConfig {
                ServiceName = Config.ServiceName,
                OperationsNamespace = Config.OperationNamespace,
                ServiceModelFinder = ServiceModelFinder.Instance,
                ServiceController = new ServiceController(new ServiceResolver()),
            });
        }
コード例 #5
0
 public void A_registered_db4o_provider_manager_can_be_resolved()
 {
     var db4oProvider = new Db4OFileProviderManager("test.db4o");
     var factory = new FactoryProvider(this.factoryConfig);
     factory.Register(db4oProvider);
     var provider = factory.Resolve<IPersistenceProviderManager>();
 }
コード例 #6
0
        public void A_registered_db4o_provider_manager_can_be_resolved()
        {
            var db4oProvider = new Db4OFileProviderManager("test.db4o");
            var factory      = new FactoryProvider(this.factoryConfig);

            factory.Register(db4oProvider);
            var provider = factory.Resolve <IPersistenceProviderManager>();
        }
コード例 #7
0
        public void A_RsaPrivateKey_can_be_created_and_configured_in_code()
        {
            var privateKey = new RsaPrivateKey(ConfigUtils.GetAppSetting("ServerPrivateKey"));
            var factory    = new FactoryProvider(this.factoryConfig);

            factory.Register(privateKey);
            var resolvedPrivateKey = factory.Resolve <RsaPrivateKey>();

            Assert.That(resolvedPrivateKey, Is.Not.Null);
        }
        public void Can_create_ClassWithAResolvableContructors()
        {
            var request = new ClassWithIntConstructor(1);

            var factory = new FactoryProvider();
            factory.Register(new HttpRequestContext(request, null));
            factory.Register(new BasicApplicationContext(null, null, null));

            var typeFactory = CreateWithFactory(factory);

            var result = typeFactory.Create(typeof(ClassWithAResolvableContructors));

            var newInstance = result as ClassWithAResolvableContructors;
            Assert.That(newInstance, Is.Not.Null);

            Assert.That(newInstance.RequestContext, Is.Not.Null);
            Assert.That(newInstance.ApplicationContext, Is.Not.Null);

            var resolvedRequest = ((HttpRequestContext)newInstance.RequestContext).Dto as ClassWithIntConstructor;
            Assert.That(resolvedRequest, Is.Not.Null);
            Assert.That(resolvedRequest.IntValue, Is.EqualTo(1));
        }
        public void ClassWithResolvableAndMultipleContructors_should_pick_contructor_with_most_params()
        {
            var request = new ClassWithIntConstructor(1);

            var factory = new FactoryProvider();
            factory.Register(new HttpRequestContext(request, null));
            factory.Register(new BasicApplicationContext(null, null, null));

            var typeFactory = CreateWithFactory(factory);

            var result = typeFactory.Create(typeof(ClassWithResolvableAndMultipleContructors));

            var newInstance = result as ClassWithResolvableAndMultipleContructors;
            Assert.That(newInstance, Is.Not.Null);

            Assert.That(newInstance.RequestContext, Is.Not.Null);
            Assert.That(newInstance.ApplicationContext, Is.Not.Null);
            Assert.That(newInstance.IntValue, Is.EqualTo(default(int)));

            var resolvedRequest = ((HttpRequestContext)newInstance.RequestContext).Dto as ClassWithIntConstructor;
            Assert.That(resolvedRequest, Is.Not.Null);
            Assert.That(resolvedRequest.IntValue, Is.EqualTo(1));
        }
コード例 #10
0
 public void A_RsaPrivateKey_can_be_created_and_configured_in_code()
 {
     var privateKey = new RsaPrivateKey(ConfigUtils.GetAppSetting("ServerPrivateKey"));
     var factory = new FactoryProvider(this.factoryConfig);
     factory.Register(privateKey);
     var resolvedPrivateKey = factory.Resolve<RsaPrivateKey>();
     Assert.That(resolvedPrivateKey, Is.Not.Null);
 }