RIA / Domain Services

Domain Services integration requires the Autofac.Extras.DomainServices NuGet package.

Quick Start

To get Autofac integrated with RIA/domain services app you need to reference the Domain Services integration NuGet package, register services, and register the integration module.

public class Global : HttpApplication, IContainerProviderAccessor
  // The IContainerProviderAccessor and IContainerProvider
  // interfaces are part of the web integration and are used
  // for registering/resolving dependencies on a per-request
  // basis.
  private static IContainerProvider _containerProvider;

  public IContainerProvider ContainerProvider
    get { return _containerProvider; }

  protected void Application_Start(object sender, EventArgs e)
    var builder = new ContainerBuilder();

    // Register your domain services.

    // Add the RIA Services module so the "Initialize"
    // method gets called on your resolved services.

    // Build the container and set the container provider
    // as in standard web integration.
    var container = builder.Build();
    _containerProvider = new ContainerProvider(container);

    // Replace the DomainService.Factory with
    // AutofacDomainServiceFactory so things get resolved.
    var factory = new AutofacDomainServiceFactory(_containerProvider);
    DomainService.Factory = factory;

When you write your domain services, use constructor injection and other standard patterns just like any other Autofac/IoC usage.


The Autofac examples repository (at tag 3.5.2) has a Domain Services project that is consumed by a Silverlight application.