コード例 #1
0
        public void GetServicesReturnsRegisteredServices()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object()).InstancePerRequest();
            builder.Register(c => new object()).InstancePerRequest();
            var lifetimeScope = builder.Build().BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
            var resolver = new AutofacWebApiDependencyScope(lifetimeScope);

            var services = resolver.GetServices(typeof(object));

            Assert.That(services.Count(), Is.EqualTo(2));
        }
コード例 #2
0
        public void GetServicesReturnsEmptyEnumerableForUnregisteredService()
        {
            var lifetimeScope = new ContainerBuilder().Build().BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
            var dependencyScope = new AutofacWebApiDependencyScope(lifetimeScope);

            var services = dependencyScope.GetServices(typeof(object));

            Assert.That(services.Count(), Is.EqualTo(0));
        }
コード例 #3
0
        public void GetServicesReturnsRegisteredService()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object()).InstancePerApiRequest();
            var lifetimeScope = builder.Build().BeginLifetimeScope(AutofacWebApiDependencyResolver.ApiRequestTag);
            var dependencyScope = new AutofacWebApiDependencyScope(lifetimeScope);

            var services = dependencyScope.GetServices(typeof(object));

            Assert.That(services.Count(), Is.EqualTo(1));
        }