This project is read-only.

Autofac Error

Topics: Customizing Orchard, Writing modules
May 14, 2012 at 8:07 PM
Edited May 14, 2012 at 8:15 PM

I created  a module PAC.ADInterface in which I have a service defined.

I am then making use of that service in one of my Theme views like this -

@using PAC.ADInterface;
    var userADService = WorkContext.Resolve<PAC.ADInterface.Services.IADUserService>();
But, I receive an exception -


The requested service 'PAC.ADInterface.Services.IADUserService' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.


Do I need to include something in my module to resolve the dependency? Please help!



May 14, 2012 at 8:10 PM

Your interface should implement IDependency at least.

May 14, 2012 at 8:15 PM
sebastienros wrote:

Your interface should implement IDependency at least.

I have that. Pls see my code below -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard;

namespace PAC.ADInterface.Services
    public interface IADUserService : IDependency
        void GetProperties(string NTID);


May 14, 2012 at 8:56 PM
Edited May 14, 2012 at 8:57 PM

The same service resolves fine if I put it inside one of the modules provided by Orchard. However, it throws an exception if I put it inside my custom module PAC.ADInterface ?

Am I missing something to include inside my module?


May 14, 2012 at 9:29 PM

You shouldn't have to do anything else. Perhaps your module is not enabled? Did you define this service class in your theme or in your module? If it's in your theme, then something is probably not setup right. I had some issues once where I created some class in a theme, but was never invoked until I moved that class to a module. However, it (code files) should work in themes as well.

May 14, 2012 at 11:05 PM

Thanks. That was it. I forgot to enable the module :(

Everything works fine now!