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


C# Core.StandardKernel类代码示例

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


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

示例1: ResultOfMethodCallWithSameArgumentsIsCached

		public void ResultOfMethodCallWithSameArgumentsIsCached()
		{
			IModule testModule = new InlineModule(m => m.Bind<CacheMock>().ToSelf());

			using (var kernel = new StandardKernel(new LinFuModule(), new CacheModule(), testModule))
			{
				var obj = kernel.Get<CacheMock>();

				CacheMock.ResetCounts();

				int result;

				result = obj.Multiply(2, 3);
				Assert.That(result, Is.EqualTo(6));
				Assert.That(CacheMock.MultiplyCount, Is.EqualTo(1));

				result = obj.Multiply(2, 3);
				Assert.That(result, Is.EqualTo(6));
				Assert.That(CacheMock.MultiplyCount, Is.EqualTo(1));

				result = obj.Multiply(4, 4);
				Assert.That(result, Is.EqualTo(16));
				Assert.That(CacheMock.MultiplyCount, Is.EqualTo(2));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:25,代码来源:CacheFixture.cs

示例2: MemberBasedBindingOfTypeDependencies

		public void MemberBasedBindingOfTypeDependencies()
		{
			IModule module = new InlineModule(
				m => m.Bind(typeof(ObjectWithMethodInterceptor)).ToSelf(),
				m => m.Intercept(When.Request.Method.Name.StartsWith("F")).With<CountInterceptor>()
			);

			using (var kernel = new StandardKernel(module))
			{
				kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory());

				var obj = kernel.Get<ObjectWithMethodInterceptor>();

				IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor));

				IRequest request = new StandardRequest(
					context,
					obj,
					typeof(ObjectWithMethodInterceptor).GetMethod("Foo"),
					new object[0],
					Type.EmptyTypes
				);

				ICollection<IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request);
				Assert.That(interceptors.Count, Is.EqualTo(2));

				IEnumerator<IInterceptor> enumerator = interceptors.GetEnumerator();

				enumerator.MoveNext();
				Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor)));

				enumerator.MoveNext();
				Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor)));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:35,代码来源:ConditionalInterceptionFixture.cs

示例3: TryingToUnloadAModuleThatIsNotLoadedThrowsException

		public void TryingToUnloadAModuleThatIsNotLoadedThrowsException()
		{
			var moduleA = new MockModuleA();

			using (var kernel = new StandardKernel())
				kernel.Unload(moduleA);
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:7,代码来源:ModuleFixture.cs

示例4: MemberBasedBindingOfTypeDependencies

		public void MemberBasedBindingOfTypeDependencies()
		{
			IModule module = new InlineModule(
				m => m.Bind(typeof(IMock)).To(typeof(ImplA)).Only(When.Context.Member.Tag.EqualTo("A")),
				m => m.Bind(typeof(IMock)).To(typeof(ImplB)).Only(When.Context.Member.Tag.EqualTo("B")),
				m => m.Bind(typeof(IMock)).To(typeof(ImplC)).Only(!When.Context.Member.Tag.EqualTo("A") & !When.Context.Member.Tag.EqualTo("B"))
			);

			using (var kernel = new StandardKernel(module))
			{
				var obj1 = kernel.Get<RequestsTagA>();
				Assert.That(obj1, Is.Not.Null);
				Assert.That(obj1.Child, Is.Not.Null);
				Assert.That(obj1.Child, Is.InstanceOfType(typeof(ImplA)));

				var obj2 = kernel.Get<RequestsTagB>();
				Assert.That(obj2, Is.Not.Null);
				Assert.That(obj2.Child, Is.Not.Null);
				Assert.That(obj2.Child, Is.InstanceOfType(typeof(ImplB)));

				var obj3 = kernel.Get<RequestsNoTag>();
				Assert.That(obj3, Is.Not.Null);
				Assert.That(obj3.Child, Is.Not.Null);
				Assert.That(obj3.Child, Is.InstanceOfType(typeof(ImplC)));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:26,代码来源:ConditionalBindingFixture.cs

示例5: StaticInterceptorsAreRegisteredFromAttributesDefinedOnMethods

		public void StaticInterceptorsAreRegisteredFromAttributesDefinedOnMethods()
		{
			var module = new InlineModule(m => m.Bind<ObjectWithMethodInterceptor>().ToSelf());

			using (var kernel = new StandardKernel(module))
			{
				kernel.Components.Connect<IProxyFactory>(new DummyProxyFactory());

				var obj = kernel.Get<ObjectWithMethodInterceptor>();

				IContext context = kernel.Components.ContextFactory.Create(typeof(ObjectWithMethodInterceptor));

				IRequest request = new StandardRequest(
					context,
					obj,
					typeof(ObjectWithMethodInterceptor).GetMethod("Foo"),
					new object[0],
					Type.EmptyTypes
				);

				ICollection<IInterceptor> interceptors = kernel.Components.AdviceRegistry.GetInterceptors(request);
				IEnumerator<IInterceptor> enumerator = interceptors.GetEnumerator();
				enumerator.MoveNext();

				Assert.That(interceptors.Count, Is.EqualTo(1));
				Assert.That(enumerator.Current, Is.InstanceOfType(typeof(CountInterceptor)));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:28,代码来源:InterceptionFixture.cs

示例6: ManyPublishersOneSubscriber

		public void ManyPublishersOneSubscriber()
		{
			using (var kernel = new StandardKernel(new MessageBrokerModule()))
			{
				PublisherMock pub1 = kernel.Get<PublisherMock>();
				PublisherMock pub2 = kernel.Get<PublisherMock>();
				Assert.That(pub1, Is.Not.Null);
				Assert.That(pub2, Is.Not.Null);

				SubscriberMock sub = kernel.Get<SubscriberMock>();
				Assert.That(sub, Is.Not.Null);

				Assert.That(pub1.HasListeners);
				Assert.That(pub2.HasListeners);
				Assert.That(sub.LastMessage, Is.Null);

				pub1.SendMessage("Hello, world!");
				Assert.That(sub.LastMessage, Is.EqualTo("Hello, world!"));

				sub.LastMessage = null;
				Assert.That(sub.LastMessage, Is.Null);

				pub2.SendMessage("Hello, world!");
				Assert.That(sub.LastMessage, Is.EqualTo("Hello, world!"));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:26,代码来源:MessageBrokerFixture.cs

示例7: StandardKernelUsesDefaultOptions

		public void StandardKernelUsesDefaultOptions()
		{
			using (var kernel = new StandardKernel())
			{
				Assert.That(kernel.Options, Is.SameAs(KernelOptions.Default));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:7,代码来源:KernelFixture.cs

示例8: CanCallParameterlessConstructor

		public void CanCallParameterlessConstructor()
		{
			using (var kernel = new StandardKernel())
			{
				var mock = kernel.Get<SimpleObject>();
				Assert.That(mock, Is.Not.Null);
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:8,代码来源:StandardProviderFixture.cs

示例9: StartableObjectIsStartedWhenActivated

		public void StartableObjectIsStartedWhenActivated()
		{
			using (var kernel = new StandardKernel())
			{
				var mock = kernel.Get<StartableMock>();
				Assert.That(mock, Is.Not.Null);
				Assert.That(mock.Started, Is.True);
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:9,代码来源:StrategySupportFixture.cs

示例10: DefiningMultipleDefaultBindingsThrowsException

		public void DefiningMultipleDefaultBindingsThrowsException()
		{
			var module = new InlineModule(
				m => m.Bind(typeof(IMock)).To(typeof(ImplA)),
				m => m.Bind(typeof(IMock)).To(typeof(ImplB))
			);

			var kernel = new StandardKernel(module);
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:9,代码来源:BindingFixture.cs

示例11: Main

        public static void Main()
        {
            IKernel kernel = new StandardKernel(new InlineModule(
                                                    m => m.Bind<IReportBuilder>().To<ReportBuilder>(),
                                                    m => m.Bind<IReportSender>().To<EmailReportSender>(),
                                                    m => m.Bind<IReporter>().To<Reporter>()
                                                    ));

            kernel.Get<IReporter>().SendReports();
        }
开发者ID:ms-lilibeth,项目名称:dotnetconf,代码行数:10,代码来源:Program.cs

示例12: SelfBoundTypeReceivesMethodInjection

		public void SelfBoundTypeReceivesMethodInjection()
		{
			using (var kernel = new StandardKernel())
			{
				var mock = kernel.Get<RequestsMethodInjection>();

				Assert.That(mock, Is.Not.Null);
				Assert.That(mock.Child, Is.Not.Null);
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:10,代码来源:MethodInjectionStrategyFixture.cs

示例13: CreateKernel

		/*----------------------------------------------------------------------------------------*/
		private static IKernel CreateKernel()
		{
			IKernel kernel = new StandardKernel();

			// The test will not pass with just the StandardKernel, because the NullLoggerFactory
			// returns the same instance of NullLogger to use as a flyweight.
			kernel.Components.Connect<ILoggerFactory>(new ConsoleLoggerFactory());

			return kernel;
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:11,代码来源:LoggerResolverFixture.cs

示例14: OptionalDependenciesForServiceBoundTypesAreIgnoredIfNoBindingsExist

		public void OptionalDependenciesForServiceBoundTypesAreIgnoredIfNoBindingsExist()
		{
			using (var kernel = new StandardKernel())
			{
				RequestsOptionalService parent = kernel.Get<RequestsOptionalService>();

				Assert.That(parent, Is.Not.Null);
				Assert.That(parent.Child, Is.Null);
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:10,代码来源:OptionalBindingFixture.cs

示例15: ConstructorReceivesInjection

		public void ConstructorReceivesInjection()
		{
			using (var kernel = new StandardKernel())
			{
				var mock = kernel.Get<RequestsConstructorInjection>();

				Assert.That(mock, Is.Not.Null);
				Assert.That(mock.Child, Is.Not.Null);
				Assert.That(mock.Child, Is.InstanceOfType(typeof(SimpleObject)));
			}
		}
开发者ID:jamarlthomas,项目名称:ninject1,代码行数:11,代码来源:StandardProviderFixture.cs


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