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

C# IoC.ServiceLocator类代码示例

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

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



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


示例16: InitializeServiceLocatorFromNonDefaultConfiguration

        public void InitializeServiceLocatorFromNonDefaultConfiguration()
        {
            Configuration openExeConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var configurationSection = openExeConfiguration.GetSection<IoCConfigurationSection>("ioc", "catel");
            var serviceLocatorConfiguration = configurationSection.GetServiceLocatorConfiguration("test");
            Assert.IsNotNull(serviceLocatorConfiguration);

            var serviceLocator = new ServiceLocator();
            serviceLocatorConfiguration.Configure(serviceLocator);

            Assert.AreEqual(serviceLocatorConfiguration.SupportDependencyInjection, serviceLocator.SupportDependencyInjection);
            foreach (Registration registration in serviceLocatorConfiguration)
            {
                serviceLocator.IsTypeRegistered(registration.InterfaceType);
                if (registration.RegistrationType == RegistrationType.Singleton)
                {
                    serviceLocator.IsTypeRegisteredAsSingleton(registration.InterfaceType);
                }
            }
        }
开发者ID:pars87,项目名称:Catel,代码行数:20,代码来源:IoCConfigurationSectionTests.cs


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


示例18: RegistersTheBootTasksAndCallsCommitAsync

 public void RegistersTheBootTasksAndCallsCommitAsync()
 {
     var splashScreenServiceMock = new Mock<ISplashScreenService>();
     var serviceLocator = new ServiceLocator();
     serviceLocator.RegisterInstance<ISplashScreenService>(splashScreenServiceMock.Object);
     new FooBootstrapper(serviceLocator).RunWithSplashScreen<ProgressNotifyableViewModel>();
     splashScreenServiceMock.Verify(service => service.Enqueue(It.IsAny<ITask>()), Times.AtLeast(12));
     splashScreenServiceMock.Verify(service => service.CommitAsync<ProgressNotifyableViewModel>(null), Times.Once());
 }
开发者ID:pars87,项目名称:Catel,代码行数:9,代码来源:BootstrapperBaseTests.cs


示例19: TheOpenedActionIsCalledWhenViewManagerHaveRegisteredAViewForTheViewModel

            public void TheOpenedActionIsCalledWhenViewManagerHaveRegisteredAViewForTheViewModel()
            {
                 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[] { new FooViewModelView(fooViewModel) });
                
                serviceLocator.RegisterInstance<IDispatcherService>(dispatcherServiceMock.Object);
            	serviceLocator.RegisterInstance<IUIVisualizerService>(visualizerServiceMock.Object);
            	serviceLocator.RegisterInstance<IViewManager>(viewManagerMock.Object);
            
                serviceLocator.ResolveType<IUIVisualizerService>().Show(fooViewModel, () =>
                    {
                        visualizerServiceMock.Verify(service => service.Show(It.Is<FooViewModel>(model => ReferenceEquals(model, fooViewModel)), null), Times.Once());
                        viewManagerMock.Verify(manager => manager.GetViewsOfViewModel(fooViewModel), Times.AtLeastOnce());  
                        this.EnqueueTestComplete();
                    });
            }
开发者ID:pars87,项目名称:Catel,代码行数:23,代码来源:UIVisualizerServiceExtensionsTests.cs


示例20: UnknowModuleBootstrapper

 /// <summary>
 /// Initializes a new instance of the <see cref="UnknowModuleBootstrapper"/> class. 
 /// </summary>
 /// <param name="serviceLocator">
 /// The service locator.
 /// </param>
 public UnknowModuleBootstrapper(ServiceLocator serviceLocator)
     : base(serviceLocator)
 {
 }
开发者ID:pars87,项目名称:Catel,代码行数:10,代码来源:BootstrapperBaseTests.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# DbContextTest.TestDbContextContainer类代码示例发布时间:2022-05-24
下一篇:
C# Data.ValidationContext类代码示例发布时间: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