• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IocContainer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetServiceTest2

 public void GetServiceTest2()
 {
     var type = typeof(DefaultService1);
     var container = new IocContainer();
     container.AddService(type, true);
     var childContainer = new IocContainer(container);
     Assert.Equal(childContainer.GetService(type), container.GetService(type));
 }
开发者ID:glorylee,项目名称:Aoite,代码行数:8,代码来源:IocContainerTests.cs


示例17: AddService_TypeObjectBoolean_Test1

        public void AddService_TypeObjectBoolean_Test1()
        {
            var container = new IocContainer();
            container.AddService(typeof(IService2), new XService2());

            var childContainer = new IocContainer(container);
            Assert.IsAssignableFrom<XService2>(childContainer.GetService(typeof(IService2)));
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:8,代码来源:IocContainerTests.cs


示例18: CanSetProvider

        public void CanSetProvider()
        {
            var resolver = new IocContainer();
            var locator = new DynamoServiceLocator(resolver);
            ServiceLocator.SetLocatorProvider(() => locator);

            // No way to get provider from ServiceLocator.Current to verify!!
        }
开发者ID:GeorgeR,项目名称:DynamoIOC,代码行数:8,代码来源:Tests.cs


示例19: PrepareBasic

        public override void PrepareBasic()
        {
            this.container = new IocContainer();

            this.RegisterDummies();
            this.RegisterStandard();
            this.RegisterComplex();
        }
开发者ID:CodeDux,项目名称:IocPerformance,代码行数:8,代码来源:MunqContainerAdapter.cs


示例20: ResolveAllByTypeNotRegisteredThrowsException

		public void ResolveAllByTypeNotRegisteredThrowsException()
		{
			using (var container = new IocContainer())
			{
				var results = container.ResolveAll<IFoo>();

				// Doesnt throw exception before it is enumerated because it uses yield return - OK ?
				var test = results.Count();
			}
		}
开发者ID:Kingefosa,项目名称:Dynamo.IoC,代码行数:10,代码来源:ResolveAllTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Ionic类代码示例发布时间:2022-05-24
下一篇:
C# IoSession类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap