コード例 #1
0
        public void GetServiceReturnsNullForUnregisteredService()
        {
            var lifetimeScope = new ContainerBuilder().Build().BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
            var dependencyScope = new AutofacWebApiDependencyScope(lifetimeScope);

            var service = dependencyScope.GetService(typeof(object));

            Assert.That(service, Is.Null);
        }
コード例 #2
0
        public void GetServiceReturnsRegisteredService()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object()).InstancePerRequest();
            var lifetimeScope = builder.Build().BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
            var dependencyScope = new AutofacWebApiDependencyScope(lifetimeScope);

            var service = dependencyScope.GetService(typeof(object));

            Assert.That(service, Is.Not.Null);
        }
コード例 #3
0
        public void HandlerUpdatesDependencyScopeWithHttpRequestMessage()
        {
            var request = new HttpRequestMessage();
            var lifetimeScope = new ContainerBuilder().Build().BeginLifetimeScope(AutofacWebApiDependencyResolver.ApiRequestTag);
            var scope = new AutofacWebApiDependencyScope(lifetimeScope);
            request.Properties.Add(HttpPropertyKeys.DependencyScope, scope);

            CurrentRequestHandler.UpdateScopeWithHttpRequestMessage(request);

            Assert.That(scope.GetService(typeof(HttpRequestMessage)), Is.EqualTo(request));
        }
コード例 #4
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));
        }
コード例 #5
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));
        }
コード例 #6
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));
        }