예제 #1
0
        public void ShouldResolveGenericDependenciesFromManuallyConstructedTypeInstances()
        {
            // Arrange
            Type servicerInstanceType = typeof(IServicer <>);
            Type recipientAType       = typeof(ServiceRecipientA);
            Type recipientBType       = typeof(ServiceRecipientB);
            Type servicerAType        = servicerInstanceType.MakeGenericType(recipientAType);
            Type servicerBType        = servicerInstanceType.MakeGenericType(recipientBType);

            // Act
            IServicer <ServiceRecipientA>
            servicerA = (BaseServiceProvider <ServiceRecipientA>)NitroxServiceLocator.LocateService(servicerAType);

            IServicer <ServiceRecipientB>
            servicerB = (BaseServiceProvider <ServiceRecipientB>)NitroxServiceLocator.LocateService(servicerBType);

            // Assert
            servicerA.Should().NotBeNull();
            servicerA.Should().BeOfType <ServiceAProvider>();
            Assert.ThrowsException <NotImplementedException>(() => servicerA.PerformService(null));

            servicerB.Should().NotBeNull();
            servicerB.Should().BeOfType <ServiceBProvider>();
            Assert.ThrowsException <NotImplementedException>(() => servicerB.PerformService(null));
        }
예제 #2
0
        public void ShouldResolveGenericDependencies()
        {
            IServicer <ServiceRecipientA>
            servicerA = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientA> >();

            IServicer <ServiceRecipientB>
            servicerB = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientB> >();

            servicerA.Should().NotBeNull();
            servicerA.Should().BeOfType <ServiceAProvider>();

            servicerB.Should().NotBeNull();
            servicerB.Should().BeOfType <ServiceBProvider>();
        }
예제 #3
0
        public void ShouldResolveGenericDependencies()
        {
            IServicer <ServiceRecipientA>
            servicerA = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientA> >();

            IServicer <ServiceRecipientB>
            servicerB = NitroxServiceLocator.LocateService <IServicer <ServiceRecipientB> >();

            servicerA.Should().NotBeNull();
            servicerA.Should().BeOfType <ServiceAProvider>();
            Assert.ThrowsException <NotImplementedException>(() => servicerA.PerformService(null));

            servicerB.Should().NotBeNull();
            servicerB.Should().BeOfType <ServiceBProvider>();
            Assert.ThrowsException <NotImplementedException>(() => servicerB.PerformService(null));
        }