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


C# ServiceLocator.RegisterType方法代码示例

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


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

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

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

示例3: ReturnsTrueForRegisteredType

            public void ReturnsTrueForRegisteredType()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterType<IMessageService, MessageService>();
                var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();

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

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

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

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

示例7: ResoleType_Generic_TransientLifestyle

            public void ResoleType_Generic_TransientLifestyle()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());

                var firstInstance = serviceLocator.ResolveType<ITestInterface>();
                Assert.IsInstanceOfType(firstInstance, typeof(TestClass1));

                var secondInstance = serviceLocator.ResolveType<ITestInterface>();
                Assert.IsInstanceOfType(secondInstance, typeof(TestClass1));

                Assert.AreNotSame(firstInstance, secondInstance);
            }
开发者ID:pars87,项目名称:Catel,代码行数:14,代码来源:ServiceLocatorFacts.cs

示例8: InvokesTypeRegisteredEvent

            public void InvokesTypeRegisteredEvent()
            {
                var serviceLocator = new ServiceLocator();

                TypeRegisteredEventArgs eventArgs = null;

                serviceLocator.TypeRegistered += (sender, args) => { eventArgs = args; };
                serviceLocator.RegisterType<ITestInterface, TestClass2>(registrationType: RegistrationType.Transient);

                Assert.IsNotNull(eventArgs);
                Assert.AreEqual(typeof(ITestInterface), eventArgs.ServiceType);
                Assert.AreEqual(typeof(TestClass2), eventArgs.ServiceImplementationType);
                Assert.AreEqual(RegistrationType.Transient, eventArgs.RegistrationType);
            }
开发者ID:pars87,项目名称:Catel,代码行数:14,代码来源:ServiceLocatorFacts.cs

示例9: ThrowsNotSupportedExceptionWhenAtLeastOneTypeIsNotRegistered

            public void ThrowsNotSupportedExceptionWhenAtLeastOneTypeIsNotRegistered()
            {
                var serviceLocator = new ServiceLocator();

                serviceLocator.RegisterType<object>();
                serviceLocator.RegisterType<ITestInterface1, TestClass1>();

                ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => serviceLocator.ResolveAllTypes(typeof(object), typeof(ITestInterface1), typeof(ITestInterface2)));
            }
开发者ID:pars87,项目名称:Catel,代码行数:9,代码来源:ServiceLocatorFacts.cs

示例10: ResolvesTypeUsingDependencyInjectionUsesConstructorWithMostParametersFirst

            public void ResolvesTypeUsingDependencyInjectionUsesConstructorWithMostParametersFirst()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterType<DependencyInjectionTestClass, DependencyInjectionTestClass>();
                var iniEntry = new IniEntry { Group = "group", Key = "key", Value = "value" };
                serviceLocator.RegisterInstance(iniEntry);
                serviceLocator.RegisterInstance(42);
                serviceLocator.RegisterInstance("hi there");

                var instance = serviceLocator.ResolveType<DependencyInjectionTestClass>();

                Assert.IsFalse(instance.UsedDefaultConstructor);
                Assert.AreEqual(iniEntry, instance.IniEntry);
                Assert.AreEqual(42, instance.IntValue);
                Assert.AreEqual("hi there", instance.StringValue);
            }
开发者ID:pars87,项目名称:Catel,代码行数:16,代码来源:ServiceLocatorFacts.cs

示例11: ResolveType_RegisteredAsTypeInServiceLocator

            public void ResolveType_RegisteredAsTypeInServiceLocator()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.RegisterType<ITestInterface, TestClass1>();

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

示例12: TheIsTypeRegisteredAsSingleton_NonSingleton

 public void TheIsTypeRegisteredAsSingleton_NonSingleton()
 {
     var serviceLocator = new ServiceLocator();
     serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
     Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton(typeof(ITestInterface)));
 }
开发者ID:pars87,项目名称:Catel,代码行数:6,代码来源:ServiceLocatorFacts.cs

示例13: TheIsTypeRegisteredAsSingleton_Generic

 public void TheIsTypeRegisteredAsSingleton_Generic()
 {
     var serviceLocator = new ServiceLocator();
     serviceLocator.RegisterType<ITestInterface, TestClass1>();
     Assert.IsTrue(serviceLocator.IsTypeRegisteredAsSingleton<ITestInterface>());
 }
开发者ID:pars87,项目名称:Catel,代码行数:6,代码来源: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: AllowsTheSameInterfaceDefinedTwiceWithDifferentTags

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

                Assert.IsFalse(serviceLocator.IsTypeRegistered(typeof(ITestInterface)));
                Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface), "1"));
                Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface), "2"));
            }
开发者ID:pars87,项目名称:Catel,代码行数:10,代码来源:ServiceLocatorFacts.cs


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