Catel.IoC.ServiceLocator.RegisterInstance C# (CSharp) Method

RegisterInstance() public method

Registers a specific instance of a service.
The is null. The is null. The is not of the right type.
public RegisterInstance ( Type serviceType, object instance, object tag = null ) : void
serviceType System.Type Type of the service.
instance object The instance.
tag object The tag to register the service with. The default value is null.
return void
        public void RegisterInstance(Type serviceType, object instance, object tag = null)
        {
            Argument.IsNotNull("serviceType", serviceType);
            Argument.IsNotNull("instance", instance);
            Argument.IsOfType("instance", instance, serviceType);

            RegisterInstance(serviceType, instance, tag, this);
        }

Same methods

ServiceLocator::RegisterInstance ( Type serviceType, object instance, object tag, object originalContainer ) : void

Usage Example

コード例 #1
0
ファイル: ViewModelBaseTest.cs プロジェクト: pars87/Catel
        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>()));
        }
All Usage Examples Of Catel.IoC.ServiceLocator::RegisterInstance