/// <summary> /// Retrieve a service instance from the context. /// </summary> /// <param name="serviceData"> /// Data object containing information about how to resolve the service /// implementation instance. /// </param> /// <returns>The service instance.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="serviceData" /> is <see langword="null" />. /// </exception> public object Resolve(ServiceImplementationData serviceData) { if (serviceData == null) { throw new ArgumentNullException("serviceData"); } return(serviceData.ImplementationResolver(this.LifetimeScope)); }
public AutofacDependencyInjectionServiceBehavior(IContainer container, ServiceImplementationData serviceData) { if (container == null) { throw new ArgumentNullException("container"); } if (serviceData == null) { throw new ArgumentNullException("serviceData"); } this.Container = container; this.ServiceData = serviceData; }
public AutofacInstanceProvider(IContainer container, ServiceImplementationData serviceData) { if (container == null) { throw new ArgumentNullException("container"); } if (serviceData == null) { throw new ArgumentNullException("serviceData"); } this.Container = container; this.ServiceData = serviceData; }
/// <summary> /// Creates the service host and attaches a WCF Service behavior that uses Autofac to resolve the service instance. /// </summary> /// <param name="serviceData">Data about which service type to host and how to resolve the implementation type.</param> /// <param name="baseAddresses">The base addresses.</param> /// <returns>A <see cref="T:System.ServiceModel.ServiceHost"/> with specific base addresses.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="serviceData" /> is <see langword="null" />. /// </exception> /// <remarks> /// <para> /// If <see cref="AutofacContrib.Multitenant.Wcf.AutofacHostFactory.HostConfigurationAction"/> /// is not <see langword="null" />, the new service host instance is run /// through the configuration action prior to being returned. This allows /// you to programmatically configure behaviors or other aspects of the /// host. /// </para> /// </remarks> protected virtual ServiceHost CreateServiceHost(ServiceImplementationData serviceData, Uri[] baseAddresses) { if (serviceData == null) { throw new ArgumentNullException("serviceData"); } var host = CreateServiceHost(serviceData.ServiceTypeToHost, baseAddresses); host.Opening += (sender, args) => host.Description.Behaviors.Add( new AutofacDependencyInjectionServiceBehavior(AutofacHostFactory.Container, serviceData)); var action = AutofacHostFactory.HostConfigurationAction; if (action != null) { action(host); } return(host); }