public void ReleaseInstance_NullInstanceContext()
 {
     var data = new ServiceImplementationData();
     var container = new ContainerBuilder().Build();
     var provider = new AutofacInstanceProvider(container, data);
     object instance = new object();
     Assert.Throws<ArgumentNullException>(() => provider.ReleaseInstance(null, instance));
 }
 public void GetInstance_NullInstanceContext()
 {
     var data = new ServiceImplementationData();
     var container = new ContainerBuilder().Build();
     var provider = new AutofacInstanceProvider(container, data);
     var message = new TestMessage();
     Assert.Throws<ArgumentNullException>(() => provider.GetInstance(null, message));
 }
        public void LifetimeScopeDisposedWhenExceptionThrownInServiceConstructor()
        {
            var builder = new ContainerBuilder();
            var released = false;
            builder.RegisterType<Disposable>().OnRelease(d => released = true);
            builder.RegisterType<BadService>();
            var container = builder.Build();
            var data = new ServiceImplementationData { ImplementationResolver = l => l.Resolve<BadService>() };
            var provider = new AutofacInstanceProvider(container, data);
            var context = new InstanceContext(new object());

            Assert.Throws<DependencyResolutionException>(() => provider.GetInstance(context));

            Assert.True(released);
        }
        public void Dispose_InstancesDisposed()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<DisposeTracker>();
            var container = builder.Build();

            var impData = new ServiceImplementationData()
            {
                ConstructorString = "TestService",
                ServiceTypeToHost = typeof(DisposeTracker),
                ImplementationResolver = l => l.Resolve<DisposeTracker>()
            };

            var context = new AutofacInstanceContext(container);
            var disposable = (DisposeTracker)context.Resolve(impData);
            Assert.False(disposable.IsDisposedPublic);
            context.Dispose();
            Assert.True(disposable.IsDisposedPublic);
        }
 public void Ctor_RequiresContainer()
 {
     var data = new ServiceImplementationData();
     Assert.Throws<ArgumentNullException>(() => new AutofacDependencyInjectionServiceBehavior(null, data));
 }
 public void Ctor_RequiresContainer()
 {
     var data = new ServiceImplementationData();
     Assert.Throws<ArgumentNullException>(() => new AutofacInstanceProvider(null, data));
 }