Ejemplo n.º 1
0
    // lots of code removed...
    public object GetInstance(InstanceContext instanceContext, Message message)
    {
        if (instanceContext == null)
        {
            throw new ArgumentNullException("instanceContext");
        }
        var extension = new AutofacInstanceContext(_rootLifetimeScope);

        instanceContext.Extensions.Add(extension);
        return(extension.Resolve(_serviceData));
    }
        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.IsFalse(disposable.IsDisposedPublic);
            context.Dispose();
            Assert.IsTrue(disposable.IsDisposedPublic);
        }
        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.IsFalse(disposable.IsDisposedPublic);
            context.Dispose();
            Assert.IsTrue(disposable.IsDisposedPublic);
        }
        public void Resolve_RequiresServiceImplementationData()
        {
            var context = new AutofacInstanceContext(new ContainerBuilder().Build());

            Assert.Throws <ArgumentNullException>(() => context.Resolve(null));
        }
 public void Resolve_RequiresServiceImplementationData()
 {
     var context = new AutofacInstanceContext(new ContainerBuilder().Build());
     Assert.Throws<ArgumentNullException>(() => context.Resolve(null));
 }
        /// <summary>
        /// Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"/> object.
        /// </summary>
        /// <param name="instanceContext">The current <see cref="T:System.ServiceModel.InstanceContext"/> object.</param>
        /// <param name="message">The message that triggered the creation of a service object.</param>
        /// <returns>The service object.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if <paramref name="instanceContext" /> is <see langword="null" />.
        /// </exception>
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            if (instanceContext == null)
            {
                throw new ArgumentNullException("instanceContext");
            }

            var autofacInstanceContext = new AutofacInstanceContext(_rootLifetimeScope);
            instanceContext.Extensions.Add(autofacInstanceContext);

            try
            {
                return autofacInstanceContext.Resolve(_serviceData);
            }
            catch (Exception)
            {
                autofacInstanceContext.Dispose();
                instanceContext.Extensions.Remove(autofacInstanceContext);
                throw;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"/> object.
 /// </summary>
 /// <param name="instanceContext">The current <see cref="T:System.ServiceModel.InstanceContext"/> object.</param>
 /// <param name="message">The message that triggered the creation of a service object.</param>
 /// <returns>The service object.</returns>
 /// <exception cref="System.ArgumentNullException">
 /// Thrown if <paramref name="instanceContext" /> is <see langword="null" />.
 /// </exception>
 public object GetInstance(InstanceContext instanceContext, Message message)
 {
     if (instanceContext == null)
     {
         throw new ArgumentNullException("instanceContext");
     }
     var extension = new AutofacInstanceContext(_rootLifetimeScope);
     instanceContext.Extensions.Add(extension);
     return extension.Resolve(_serviceData);
 }