本文整理汇总了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;
}
示例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>());
}
示例3: ReturnsTrueForRegisteredType
public void ReturnsTrueForRegisteredType()
{
var serviceLocator = new ServiceLocator();
serviceLocator.RegisterType<IMessageService, MessageService>();
var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
Assert.IsTrue(dependencyResolver.CanResolve(typeof(IMessageService)));
}
示例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>());
}
示例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);
}
示例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>());
}
示例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);
}
示例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);
}
示例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)));
}
示例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);
}
示例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));
}
示例12: TheIsTypeRegisteredAsSingleton_NonSingleton
public void TheIsTypeRegisteredAsSingleton_NonSingleton()
{
var serviceLocator = new ServiceLocator();
serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton(typeof(ITestInterface)));
}
示例13: TheIsTypeRegisteredAsSingleton_Generic
public void TheIsTypeRegisteredAsSingleton_Generic()
{
var serviceLocator = new ServiceLocator();
serviceLocator.RegisterType<ITestInterface, TestClass1>();
Assert.IsTrue(serviceLocator.IsTypeRegisteredAsSingleton<ITestInterface>());
}
示例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());
}
示例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"));
}