Exemplo n.º 1
0
        public void Get_all_instances_of_not_registered_service_should_return_empty_collection()
        {
            var locator = new DryIocServiceLocator(new Container());

            var clients = locator.GetAllInstances <IClient>().ToArray();

            Assert.That(clients.Length, Is.EqualTo(0));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Configures the LocatorProvider for the <see cref="ServiceLocator" />.
        /// </summary>
        protected override void ConfigureServiceLocator()
        {
            DryIocServiceLocator serviceLocator = new DryIocServiceLocator(Container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            // register the locator in DryIoc as well
            Container.RegisterInstance <IServiceLocator>(serviceLocator);
        }
Exemplo n.º 3
0
        public void Get_instance_of_not_registered_service_should_Throw()
        {
            var locator = new DryIocServiceLocator(new Container());

            locator.Container.Register <IClient, Client>();

            Assert.Throws <ActivationException>(() =>
                                                locator.GetInstance <IClient>());
        }
Exemplo n.º 4
0
        public void Can_get_keyed_instance_with_locator()
        {
            var locator = new DryIocServiceLocator(new Container());

            locator.Container.Register <IService, Service>(serviceKey: "1");

            var service = locator.GetInstance <IService>("1");

            Assert.That(service, Is.InstanceOf <Service>());
        }
Exemplo n.º 5
0
        public void Can_get_instance_with_locator()
        {
            var locator = new DryIocServiceLocator(new Container());

            locator.Container.Register <IClient, Client>();
            locator.Container.Register <IService, Service>();

            var client = locator.GetInstance <IClient>();

            Assert.That(client.Dependency, Is.InstanceOf <Service>());
        }
Exemplo n.º 6
0
        public void Can_get_all_instances_with_locator()
        {
            var locator = new DryIocServiceLocator(new Container());

            locator.Container.Register <IService, Service>();
            locator.Container.Register <IService, AnotherService>(serviceKey: "another");

            var services = locator.GetAllInstances <IService>().ToArray();

            Assert.That(services.Length, Is.EqualTo(2));
        }