My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
RIAServices  
Domain service factory for RIA Services
Autofac2
Updated Aug 6, 2010 by carl.hoerberg

Introduction

This module is written to allow dependency injection in DomainServices in RIA projects.

Required References

  • Autofac.dll
  • System.ServiceModel.DomainServices.Server.dll (Deployed to GAC if you installed RIA Services)
  • AutofacContrib.DomainServices.dll

Getting Started

Create a domain service:

    public class MyDomainService : DomainService
    {
        protected readonly ISession Session;
        protected MyDomainService(ISession session)
        {
            Session = session;
	}
		
	// Your methods
    }

Setup Global.asax by register your DomainServices, register the DomainServicesModule module from the contrib project and finally replace the DomainService factory with AutofacDomainServiceFactory.

    public class Global : HttpApplication, IContainerProviderAccessor
    {

        protected void Application_Start(object sender, EventArgs e)
        {
		 var builder = new ContainerBuilder();
		 // Register your domain services
                 builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AssignableTo<DomainService>();
		 
		 // Add the RIA Services module
		 builder.RegisterModule<DomainServicesModule>(); 		
		 
		 // Build as normal
		 var container = builder.Build();
		 _containerProvider = new ContainerProvider(container);
		 
		 // Replace the DomainService.Factory with AutofacDomainServiceFactory
		 DomainService.Factory = new AutofacDomainServiceFactory(container); 
	}
		
	static IContainerProvider _containerProvider;
        public IContainerProvider ContainerProvider
        {
            get { return _containerProvider; }
        }
    }
Comment by asa...@gmail.com, Jul 15, 2010

I think it should be:

// Add the RIA Services module
builder.RegisterModule<AutofacDomainServiceModule>(); 
Comment by dan...@gmail.com, Mar 30, 2011

Sign in to add a comment
Powered by Google Project Hosting