當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。