本文整理汇总了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);
}
示例2: ThrowsArgumentExceptionForNullTypes
public void ThrowsArgumentExceptionForNullTypes()
{
var serviceLocator = new ServiceLocator();
var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
ExceptionTester.CallMethodAndExpectException<ArgumentException>(() => dependencyResolver.CanResolveAll(null));
}
示例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);
}
示例4: ReturnsTrueForEmptyArray
public void ReturnsTrueForEmptyArray()
{
var serviceLocator = new ServiceLocator();
var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
Assert.IsTrue(dependencyResolver.CanResolveAll(new Type[] { }));
}
示例5: ReturnsFalseForNonRegisteredType
public void ReturnsFalseForNonRegisteredType()
{
var serviceLocator = new ServiceLocator();
var dependencyResolver = serviceLocator.ResolveType<IDependencyResolver>();
Assert.IsFalse(dependencyResolver.CanResolve(typeof(IMessageService)));
}
示例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>());
}
示例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>());
}
示例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>());
}
示例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);
}
示例10: ResolvesTypeUsingDependencyInjectionFallBackToDefaultConstructor
public void ResolvesTypeUsingDependencyInjectionFallBackToDefaultConstructor()
{
var serviceLocator = new ServiceLocator();
var typeFactory = serviceLocator.ResolveType<ITypeFactory>();
var instance = typeFactory.CreateInstance<DependencyInjectionTestClass>();
Assert.IsTrue(instance.UsedDefaultConstructor);
}
示例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));
}
示例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));
}
示例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;
}
示例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);
}
示例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>()));
}