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


C# IoC.ServiceLocator类代码示例

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


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

示例1: GetAllInstanceJustReturnsCollectionOfWithOnylOneResolvedInstanceOfNonRegisteredNonAbstractClasses

 public void GetAllInstanceJustReturnsCollectionOfWithOnylOneResolvedInstanceOfNonRegisteredNonAbstractClasses()
 {
     var serviceLocator = new ServiceLocator();
     var serviceLocatorAdapter = new ServiceLocatorAdapter(serviceLocator);
     FooNonAbstractClass[] list = serviceLocatorAdapter.GetAllInstances<FooNonAbstractClass>().ToArray();
     Assert.AreEqual(1, list.Length);
 }
开发者ID:pars87,项目名称:Catel,代码行数:7,代码来源:ServiceLocatorAdapterTests.cs

示例2: 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

示例3: GetAllInstanceJustReturnsEmptyCollectionIfTheTypeIsNonRegistered

 public void GetAllInstanceJustReturnsEmptyCollectionIfTheTypeIsNonRegistered()
 {
     var serviceLocator = new ServiceLocator();
     var serviceLocatorAdapter = new ServiceLocatorAdapter(serviceLocator);
     IFooInterface[] list = serviceLocatorAdapter.GetAllInstances<IFooInterface>().ToArray();
     Assert.AreEqual(0, list.Length);
 }
开发者ID:pars87,项目名称:Catel,代码行数:7,代码来源:ServiceLocatorAdapterTests.cs

示例4: 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

示例5: 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

示例6: ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromNinjectContainer

 public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromNinjectContainer()
 {
     var serviceLocator = new ServiceLocator();
     var standardKernel = new StandardKernel();
     serviceLocator.RegisterExternalContainer(standardKernel);
     serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
     Assert.AreNotSame(standardKernel.Get<ITestInterface>(), standardKernel.Get<ITestInterface>());
 }
开发者ID:pars87,项目名称:Catel,代码行数:8,代码来源:ServiceLocatorFacts.cs

示例7: ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromUnityContainer

 public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromUnityContainer()
 {
     var serviceLocator = new ServiceLocator();
     var unityContainer = new UnityContainer();
     serviceLocator.RegisterExternalContainer(unityContainer);
     serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
     Assert.AreNotSame(unityContainer.Resolve<ITestInterface>(), unityContainer.Resolve<ITestInterface>());
 }
开发者ID:pars87,项目名称:Catel,代码行数:8,代码来源:ServiceLocatorFacts.cs

示例8: ResolvesInstancesOfTypeRegisteredWithSingletonParameterToTrueFromWindsorContainer

 public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToTrueFromWindsorContainer()
 {
     var serviceLocator = new ServiceLocator();
     var windsorContainer = new WindsorContainer();
     serviceLocator.RegisterExternalContainer(windsorContainer);
     serviceLocator.RegisterType<ITestInterface, TestClass1>();
     Assert.AreSame(windsorContainer.Resolve<ITestInterface>(), windsorContainer.Resolve<ITestInterface>());
 }
开发者ID:pars87,项目名称:Catel,代码行数:8,代码来源:ServiceLocatorFacts.cs

示例9: GetAllInstanceJustReturnsCollectionOfWithOnylOneResolvedInstanceIfTheTypeIsRegistered

 public void GetAllInstanceJustReturnsCollectionOfWithOnylOneResolvedInstanceIfTheTypeIsRegistered()
 {
     var serviceLocator = new ServiceLocator();
     serviceLocator.RegisterType<IFooInterface, FooNonAbstractClass>();
     var serviceLocatorAdapter = new ServiceLocatorAdapter(serviceLocator);
     IFooInterface[] list = serviceLocatorAdapter.GetAllInstances<IFooInterface>().ToArray();
     Assert.AreEqual(1, list.Length);
 }
开发者ID:pars87,项目名称:Catel,代码行数:8,代码来源:ServiceLocatorAdapterTests.cs

示例10: 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

示例11: 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

示例12: 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

示例13: Prepare

        public override void Prepare()
        {
            var serviceLocator = new ServiceLocator();

            serviceLocator.RegisterType<ISingleton, Singleton>(RegistrationType.Singleton);

            serviceLocator.RegisterType<ITransient, Transient>(RegistrationType.Transient);

            serviceLocator.RegisterType<ICombined, Combined>(RegistrationType.Transient);

            container = serviceLocator;
        }
开发者ID:junxy,项目名称:IocPerformance,代码行数:12,代码来源:CatelContainerAdapter.cs

示例14: DisposesAllDisposableInstances

            public void DisposesAllDisposableInstances()
            {
                var isDisposed = false;

                var disposable = new Disposable();
                disposable.Disposed += (sender, e) => isDisposed = true;

                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterInstance(typeof(Disposable), disposable);

                serviceLocator.Dispose();

                Assert.IsTrue(isDisposed);
            }
开发者ID:yshbchenlie,项目名称:Catel,代码行数:14,代码来源:ServiceLocatorFacts.cs

示例15: Constructor_InjectedServiceLocator

        public void Constructor_InjectedServiceLocator()
        {
            var serviceLocator = new ServiceLocator();
            var messageService = new MessageService();
            serviceLocator.RegisterInstance<IMessageService>(messageService);

            var navigationService = new NavigationService();
            serviceLocator.RegisterInstance<INavigationService>(navigationService);

            var viewModel = new TestViewModel(serviceLocator);
            Assert.AreEqual(messageService, viewModel.GetService<IMessageService>());
            Assert.IsTrue(ReferenceEquals(messageService, viewModel.GetService<IMessageService>()));
            Assert.AreEqual(navigationService, viewModel.GetService<INavigationService>());
            Assert.IsTrue(ReferenceEquals(navigationService, viewModel.GetService<INavigationService>()));
        }
开发者ID:pars87,项目名称:Catel,代码行数:15,代码来源:ViewModelBaseTest.cs


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