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


C# ServiceLocator.ResolveType方法代码示例

本文整理汇总了C#中Catel.IoC.ServiceLocator.ResolveType方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceLocator.ResolveType方法的具体用法?C# ServiceLocator.ResolveType怎么用?C# ServiceLocator.ResolveType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Catel.IoC.ServiceLocator的用法示例。


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

示例1: ThrowsArgumentExceptionForNullTypes

            public void ThrowsArgumentExceptionForNullTypes()
            {
                var serviceLocator = new ServiceLocator();
                var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();

                ExceptionTester.CallMethodAndExpectException<ArgumentException>(() => dependencyResolver.CanResolveAll(null));
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:7,代码来源:CatelDependencyResolverFacts.cs

示例2: ReturnsTrueForEmptyArray

            public void ReturnsTrueForEmptyArray()
            {
                var serviceLocator = new ServiceLocator();
                var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();

                Assert.IsTrue(dependencyResolver.CanResolveAll(new Type[] { }));
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:7,代码来源:CatelDependencyResolverFacts.cs

示例3: ReturnsFalseForNonRegisteredType

            public void ReturnsFalseForNonRegisteredType()
            {
                var serviceLocator = new ServiceLocator();
                var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();

                Assert.IsFalse(dependencyResolver.CanResolve(typeof(IMessageService)));
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:7,代码来源:CatelDependencyResolverFacts.cs

示例4: ReturnsTypeFactoryUsedToCreateObject

            public void ReturnsTypeFactoryUsedToCreateObject()
            {
                var serviceLocator = new ServiceLocator();
                var typeFactory = serviceLocator.ResolveType<ITypeFactory>();
                var obj = typeFactory.CreateInstance<object>();

                var usedTypeFactory = obj.GetTypeFactory();

                Assert.IsTrue(ReferenceEquals(typeFactory, usedTypeFactory));
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:10,代码来源:ObjectExtensionsFacts.cs

示例5: ReturnsDependencyResolverUsedToCreateObject

            public void ReturnsDependencyResolverUsedToCreateObject()
            {
                var serviceLocator = new ServiceLocator();
                var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
                var typeFactory = dependencyResolver.Resolve<ITypeFactory>();
                var obj = typeFactory.CreateInstance<object>();

                var usedDependencyResolver = obj.GetDependencyResolver();

                Assert.IsTrue(ReferenceEquals(dependencyResolver, usedDependencyResolver));
            }
开发者ID:paytonli2013,项目名称:Catel,代码行数:11,代码来源:ObjectExtensionsFacts.cs

示例6: ResolvesTypeUsingDependencyInjectionFallBackToDefaultConstructor

            public void ResolvesTypeUsingDependencyInjectionFallBackToDefaultConstructor()
            {
                var serviceLocator = new ServiceLocator();
                var typeFactory = serviceLocator.ResolveType<ITypeFactory>();

                var instance = typeFactory.CreateInstance<DependencyInjectionTestClass>();

                Assert.IsTrue(instance.UsedDefaultConstructor);
            }
开发者ID:pars87,项目名称:Catel,代码行数:9,代码来源:TypeFactoryFacts.cs

示例7: CallsCustomInitializationWhenNeeded

            public void CallsCustomInitializationWhenNeeded()
            {
                var serviceLocator = new ServiceLocator();
                var typeFactory = serviceLocator.ResolveType<ITypeFactory>();

                var instance = typeFactory.CreateInstance<DependencyInjectionTestClass>();
                Assert.IsTrue(instance.HasCalledCustomInitialization);
            }
开发者ID:pars87,项目名称:Catel,代码行数:8,代码来源:TypeFactoryFacts.cs

示例8: ServiceLocator

            public void TheOpenedActionIsCalledEvenWhenThereNoViewsAvailablesInTheExpectedTimeForTheCurrentViewModelButUnlockingTheInspectionThread()
            {
                var serviceLocator = new ServiceLocator();
                var fooViewModel = new FooViewModel(serviceLocator);

                var dispatcherServiceMock = new Mock<IDispatcherService>();
                dispatcherServiceMock.Setup(service => service.Invoke(It.IsAny<Action>())).Callback((Action action) => action.Invoke());
                var visualizerServiceMock = new Mock<IUIVisualizerService>();
                visualizerServiceMock.Setup(service => service.Show(It.Is<FooViewModel>(model => ReferenceEquals(model, fooViewModel)), null)).Returns(true);
                var viewManagerMock = new Mock<IViewManager>();
                viewManagerMock.Setup(manager => manager.GetViewsOfViewModel(fooViewModel)).Returns(new IView[] { });

                serviceLocator.RegisterInstance<IDispatcherService>(dispatcherServiceMock.Object);
                serviceLocator.RegisterInstance<IUIVisualizerService>(visualizerServiceMock.Object);
                serviceLocator.RegisterInstance<IViewManager>(viewManagerMock.Object);

                var @event = new AutoResetEvent(false);

                serviceLocator.ResolveType<IUIVisualizerService>().Show(fooViewModel, () => @event.Set());

                @event.WaitOne(20000);

                visualizerServiceMock.Verify(service => service.Show(It.Is<FooViewModel>(model => ReferenceEquals(model, fooViewModel)), null), Times.Once());
                viewManagerMock.Verify(manager => manager.GetViewsOfViewModel(fooViewModel), Times.AtLeastOnce());
            }
开发者ID:pars87,项目名称:Catel,代码行数:25,代码来源:UIVisualizerServiceExtensionsTests.cs

示例9: RegistersTheImplementationTypesAsInterfaceTypesIfIsSetToTrue

            public void RegistersTheImplementationTypesAsInterfaceTypesIfIsSetToTrue()
            {
                var serviceLocator = new ServiceLocator { AutoRegisterTypesViaAttributes = true };

                Assert.IsTrue(serviceLocator.IsTypeRegistered<IFooService>());
                Assert.IsTrue(serviceLocator.IsTypeRegisteredAsSingleton<IFooService>());

                Assert.IsTrue(serviceLocator.IsTypeRegistered<IFooService2>());
                Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton<IFooService2>());

                var resolveType = serviceLocator.ResolveType<IFooService>();
                Assert.IsInstanceOfType(resolveType, typeof(FooService));

                var resolveType2 = serviceLocator.ResolveType<IFooService2>();
                Assert.IsInstanceOfType(resolveType2, typeof(FooService2));
            }
开发者ID:pars87,项目名称:Catel,代码行数:16,代码来源:ServiceLocatorFacts.cs

示例10: AutomaticSynchronization_ResolveType

            public void AutomaticSynchronization_ResolveType()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = false;
                serviceLocator.RegisterType<ITestInterface, TestClass1>();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.AutomaticallyKeepContainersSynchronized = true;
                serviceLocator.ResolveType<ITestInterface>();

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
            }
开发者ID:pars87,项目名称:Catel,代码行数:12,代码来源:ServiceLocatorFacts.cs

示例11: ResolveType_RegisteredInExternalContainer

            public void ResolveType_RegisteredInExternalContainer()
            {
                var serviceLocator = new ServiceLocator();
                var ninjectContainer = new StandardKernel();
                serviceLocator.RegisterExternalContainer(ninjectContainer);
                ninjectContainer.Bind<ITestInterface>().To<TestClass1>();

                var instance = serviceLocator.ResolveType<ITestInterface>();
                Assert.IsInstanceOfType(instance, typeof(TestClass1));
            }
开发者ID:pars87,项目名称:Catel,代码行数:10,代码来源:ServiceLocatorFacts.cs

示例12: RegisterType_DoubleRegistration_ToChangeInstantiationStyle_And_Type

            public void RegisterType_DoubleRegistration_ToChangeInstantiationStyle_And_Type()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterType<ITestInterface, TestClass1>();
                var testInterfaceRef1 = serviceLocator.ResolveType<ITestInterface>();
                var testInterfaceRef2 = serviceLocator.ResolveType<ITestInterface>();
                Assert.AreSame(testInterfaceRef1, testInterfaceRef2);
                Assert.AreEqual(testInterfaceRef2.GetType(), typeof(TestClass1));

                serviceLocator.RegisterType<ITestInterface, TestClass2>(registrationType: RegistrationType.Transient);
                testInterfaceRef1 = serviceLocator.ResolveType<ITestInterface>();
                testInterfaceRef2 = serviceLocator.ResolveType<ITestInterface>();
                Assert.AreNotSame(testInterfaceRef1, testInterfaceRef2);

                Assert.AreEqual(testInterfaceRef2.GetType(), typeof(TestClass2));
            }
开发者ID:pars87,项目名称:Catel,代码行数:16,代码来源:ServiceLocatorFacts.cs

示例13: RegisterInstance_Valid

            public void RegisterInstance_Valid()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterInstance<ITestInterface>(new TestClass1 { Name = "My Instance" });

                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());

                var instance = serviceLocator.ResolveType<ITestInterface>();
                Assert.AreEqual("My Instance", instance.Name);
            }
开发者ID:pars87,项目名称:Catel,代码行数:10,代码来源:ServiceLocatorFacts.cs

示例14: OverridesRegistrationWithSameTag

            public void OverridesRegistrationWithSameTag()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterType(typeof(ITestInterface), typeof(TestClass1), "1");
                serviceLocator.RegisterType(typeof(ITestInterface), typeof(TestClass1), "2");
                serviceLocator.RegisterType(typeof(ITestInterface), typeof(TestClass2), "1");

                var firstService = serviceLocator.ResolveType(typeof(ITestInterface), "1");
                Assert.AreEqual(typeof(TestClass2), firstService.GetType());
            }
开发者ID:pars87,项目名称:Catel,代码行数:10,代码来源:ServiceLocatorFacts.cs

示例15: RemovesAllInstances

            public void RemovesAllInstances()
            {
                var serviceLocator = new ServiceLocator { AutoRegisterTypesViaAttributes = true };
                serviceLocator.RegisterType(typeof(IFoo2Service), typeof(Foo2Service), "FooService2");

                var instance1 = serviceLocator.ResolveType(typeof(IFooService), "FooService1");
                var instance2 = serviceLocator.ResolveType(typeof(IFooService), "FooService2");
                var instance3 = serviceLocator.ResolveType(typeof(IFoo2Service), "FooService2");

                serviceLocator.RemoveAllInstances();

                Assert.AreNotEqual(instance1, serviceLocator.ResolveType(typeof(IFooService), "FooService1"));
                Assert.AreNotEqual(instance2, serviceLocator.ResolveType(typeof(IFooService), "FooService2"));
                Assert.AreNotEqual(instance3, serviceLocator.ResolveType(typeof(IFoo2Service), "FooService2"));
            }
开发者ID:pars87,项目名称:Catel,代码行数:15,代码来源:ServiceLocatorFacts.cs


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