当前位置: 首页>>代码示例>>C#>>正文


C# IocContainer类代码示例

本文整理汇总了C#中IocContainer的典型用法代码示例。如果您正苦于以下问题:C# IocContainer类的具体用法?C# IocContainer怎么用?C# IocContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IocContainer类属于命名空间,在下文中一共展示了IocContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenericResolveByTypeNotRegisteredThrowsException

 public void GenericResolveByTypeNotRegisteredThrowsException()
 {
     using (var container = new IocContainer())
     {
         container.Resolve<IFoo>();
     }
 }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:7,代码来源:ResolveTest.cs

示例2: DefaultLifetimeMangerIsNull

 public void DefaultLifetimeMangerIsNull()
 {
     using (var iocContainer = new IocContainer())
     {
         Assert.IsNull(iocContainer.DefaultLifetimeManager);
     }
 }
开发者ID:jlaanstra,项目名称:Munq,代码行数:7,代码来源:DefaultLifetimeTest.cs

示例3: CanSetDefaultLifetimeToTransient

 public void CanSetDefaultLifetimeToTransient()
 {
     using (var container = new IocContainer(() => new TransientLifetime()))
     {
         Assert.IsInstanceOfType(container.DefaultLifetime, typeof(TransientLifetime));
     }
 }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:7,代码来源:TransientLifetimeTest.cs

示例4: DefaultLifetimeIsDefaultSetToTransient

 public void DefaultLifetimeIsDefaultSetToTransient()
 {
     using (var container = new IocContainer())
     {
         Assert.IsInstanceOfType(container.DefaultLifetime, typeof(TransientLifetime));
     }
 }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:7,代码来源:DefaultLifetimeTest.cs

示例5: CanSetDefaultLifetimeToSessionLifetime

		public void CanSetDefaultLifetimeToSessionLifetime()
		{
			using (var container = new IocContainer(() => new SessionLifetime()))
			{
				Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(SessionLifetime));
			}
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:7,代码来源:SessionLifetimeTest.cs

示例6: MunqUseCase

        static MunqUseCase()
        {
            container = new IocContainer();
            singleton = new Munq.LifetimeManagers.ContainerLifetime();

            container.Register<IWebService>(
                c => new WebService(
                    c.Resolve<IAuthenticator>(),
                    c.Resolve<IStockQuote>()));

            container.Register<IAuthenticator>(
                c => new Authenticator(
                    c.Resolve<ILogger>(),
                    c.Resolve<IErrorHandler>(),
                    c.Resolve<IDatabase>()));

            container.Register<IStockQuote>(
                c => new StockQuote(
                    c.Resolve<ILogger>(),
                    c.Resolve<IErrorHandler>(),
                    c.Resolve<IDatabase>()));

            container.Register<IDatabase>(
                c => new Database(
                    c.Resolve<ILogger>(),
                    c.Resolve<IErrorHandler>()));

            container.Register<IErrorHandler>(
                c => new ErrorHandler(c.Resolve<ILogger>()));

            container.RegisterInstance<ILogger>(new Logger())
                    .WithLifetimeManager(singleton);
        }
开发者ID:jlaanstra,项目名称:Munq,代码行数:33,代码来源:MunqUseCase.cs

示例7: SessionLifetimeReturnsSameInstanceForSameSessionAndDifferentInstanceForDifferentSession

		public void SessionLifetimeReturnsSameInstanceForSameSessionAndDifferentInstanceForDifferentSession()
		{
			// Arrange
			using (var container = new IocContainer())
			{
				var sessionItems1 = new SessionStateItemCollection();
				var sessionItems2 = new SessionStateItemCollection();
				var context1 = new FakeHttpContext("Http://fakeUrl1.com", null, null, null, null, sessionItems1);
				var context2 = new FakeHttpContext("Http://fakeUrl2.com", null, null, null, null, sessionItems2);

				HttpContextBase currentContext = null;

				var lifetime = new SessionLifetime(() => currentContext);		// better solution for injecting HttpContext ?

				container.Register<IFoo>(c => new Foo1()).SetLifetime(lifetime);

				// Act
				currentContext = context1;

				var result1 = container.Resolve<IFoo>();
				var result2 = container.Resolve<IFoo>();

				currentContext = context2;

				var result3 = container.Resolve<IFoo>();

				// Assert
				Assert.IsNotNull(result1);
				Assert.IsNotNull(result2);
				Assert.IsNotNull(result3);

				Assert.AreSame(result1, result2);
				Assert.AreNotSame(result1, result3);
			}
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:35,代码来源:SessionLifetimeTest.cs

示例8: Configuration

        public void Configuration(IAppBuilder appBuilder)
        {
            IIocContainer iocContainer = new IocContainer();

            Bootstrap.Application()
                .ResolveReferencesWith(iocContainer)
                .UseEnvironment()
                .UseDomain().WithSimpleMessaging()
                .ConfigureRouteInspectorServer().WithRouteLimitOf(10)
                .ConfigureRouteInspectorWeb()
                .UseEventSourcing().PersistToMemory()
                .Initialise();

            var configuration = new HttpConfiguration
            {
                DependencyResolver = new SystemDotDependencyResolver(iocContainer)
            };

            configuration.MapHttpAttributeRoutes();
            configuration.Filters.Add(new ModelStateContextFilterAttribute());
            configuration.Filters.Add(new NoCacheFilterAttribute());

            configuration.MapSynchronisationRoutes();

             configuration.Routes.MapHttpRoute(
                  "Default",
                  "{controller}/{id}",
                  new { id = RouteParameter.Optional });
            
            appBuilder.UseWebApi(configuration);
        }
开发者ID:sammosampson,项目名称:MessageRouteInspector,代码行数:31,代码来源:Startup.cs

示例9: CanSetDefaultLifetimeToThreadLocalStorageLifetime

		public void CanSetDefaultLifetimeToThreadLocalStorageLifetime()
		{
			using (var container = new IocContainer(() => new ThreadLocalLifetime()))
			{
				Assert.IsInstanceOfType(container.DefaultLifetimeFactory(), typeof(ThreadLocalLifetime));
			}
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:7,代码来源:ThreadLocalLifetimeTest.cs

示例10: ThreadLocalStorageLifetimeReturnsSameInstanceForSameThread

		public void ThreadLocalStorageLifetimeReturnsSameInstanceForSameThread()
		{
			using (var container = new IocContainer())
			{
				container.Register<IFoo>(c => new Foo1()).SetLifetime(new ThreadLocalLifetime());

				IFoo result1 = container.Resolve<IFoo>();
				IFoo result2 = container.Resolve<IFoo>();

				IFoo result3 = null;
				IFoo result4 = null;

				// Resolve on a different thread
				var task = Task.Factory.StartNew(() =>
				{
					result3 = container.Resolve<IFoo>();
					result4 = container.Resolve<IFoo>();
				});

				task.Wait();

				// Assert
				Assert.IsNotNull(result1);
				Assert.IsNotNull(result2);
				Assert.IsNotNull(result3);
				Assert.IsNotNull(result4);

				Assert.AreSame(result1, result2);
				Assert.AreSame(result3, result4);

				Assert.AreNotSame(result1, result3);
			}
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:33,代码来源:ThreadLocalLifetimeTest.cs

示例11: Prepare

 public override void Prepare()
 {
     this.container = new IocContainer();
     this.container.Register<ISingleton, Singleton>().WithLifetimeManager(new ContainerLifetime());
     this.container.Register<ITransient, Transient>().WithLifetimeManager(new AlwaysNewLifetime());
     this.container.Register<ICombined, Combined>().WithLifetimeManager(new AlwaysNewLifetime());
 }
开发者ID:junxy,项目名称:IocPerformance,代码行数:7,代码来源:MunqContainerAdapter.cs

示例12: TransientLifetimeAlwaysReturnsANewInstance

        public void TransientLifetimeAlwaysReturnsANewInstance()
        {
            // Arrange
            using (var container = new IocContainer())
            {
                container.Register<IFoo>(c => new Foo1());	//.SetLifetime(new TransientLifetime<IFoo>);

                // Act
                var result1 = container.Resolve<IFoo>();
                var result2 = container.Resolve<IFoo>();
                var result3 = container.Resolve<IFoo>();

                // Assert
                Assert.IsNotNull(result1);
                Assert.IsNotNull(result2);
                Assert.IsNotNull(result3);

                Assert.AreNotSame(result1, result2);
                Assert.AreNotSame(result2, result3);
                Assert.AreNotSame(result1, result3);

                Assert.IsInstanceOfType(result1, typeof(Foo1));
                Assert.IsInstanceOfType(result2, typeof(Foo1));
                Assert.IsInstanceOfType(result3, typeof(Foo1));
            }
        }
开发者ID:GeorgeR,项目名称:DynamoIOC,代码行数:26,代码来源:TransientLifetimeTest.cs

示例13: TryResolveAllReturnsExpectedInstances

        public void TryResolveAllReturnsExpectedInstances()
        {
            using (var container = new IocContainer())
            {
                // Arrange
                var foo1 = new Foo1();
                var foo2 = new Foo2();
                var foo3 = new Foo2();
                var bar1 = new Bar1();

                container.RegisterInstance<IFoo>(foo1);
                container.RegisterInstance<IFoo>(foo2, "Foo1");
                container.RegisterInstance<IFoo>(foo3, "Foo2");
                container.RegisterInstance<IBar>(bar1);

                // Act
                var results = container.TryResolveAll<IFoo>();

                var resultList = results.ToList();

                // Assert
                Assert.IsTrue(results.Count() == 3);

                CollectionAssert.Contains(resultList, foo1);
                CollectionAssert.Contains(resultList, foo2);
                CollectionAssert.Contains(resultList, foo3);
            }
        }
开发者ID:GeorgeR,项目名称:DynamoIOC,代码行数:28,代码来源:TryResolveAllTest.cs

示例14: GenericResolveByNameNotRegisteredThrowsException2

 public void GenericResolveByNameNotRegisteredThrowsException2()
 {
     using (var container = new IocContainer())
     {
         container.Register<IFoo>(c => new Foo1());
         container.Resolve<IFoo>("Foo");
     }
 }
开发者ID:thanhvc,项目名称:DynamoIOC,代码行数:8,代码来源:ResolveTest.cs

示例15: Application_Start

        protected void Application_Start()
        {
            IocContainer = new IocContainer();

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
开发者ID:jlaanstra,项目名称:Munq,代码行数:8,代码来源:Global.asax.cs


注:本文中的IocContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。