Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:21:30+00:00 2026-06-02T23:21:30+00:00

WCF services. My 1st attempt at IoC with WCF. Calling service from Console app

  • 0

WCF services. My 1st attempt at IoC with WCF. Calling service from Console app to test. Funny thing is I thought these services were working so I was using them to provide data to test a POC I was working on…little did I know I’d first end up fixing the services!

(Debugging using Cassini)

Versions I’m using:

  • FluentNHibernate 1.1.0.685
  • NHibernate 2.1.2.4000
  • Ninject 2.2.0.0
  • Ninject.Extensions.Wcf 2.2.0.0
  • .NET Framework 3.5

This is one of the examples I used as a reference: Pieter De Rycke’s Blog

Almost every post I found on SO deals with MVC…I assume my issue is slightly different since this is WCF not MVC.

The Exception:

Error activating IAuditRepository
No matching bindings are available, and the type is not self-bindable.
Activation path:
    2) Injection of dependency IAuditRepository into parameter auditRepository of constructor of type ShotService
    1) Request for ShotService

Suggestions:
    1) Ensure that you have defined a binding for IAuditRepository.
    2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
    3) Ensure you have not accidentally created more than one kernel.
    4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
    5) If you are using automatic module loading, ensure the search path and filters are correct.

Console app failing code: (fails on last line)

ShotServiceClient shotSvc = new ShotServiceClient();
LookupShotAdministeredRequest request = new LookupShotAdministeredRequest();
request.ClientId = "128";
request.ClinicId = "289";
request.RequestingUserId = "1";
List<ShotsAdministeredContract> shots = shotSvc.LookupShotAdministered(request).ShotsAdministered;

The Code:

Global.asax.cs

public class Global : NinjectWcfApplication
{
    protected override IKernel CreateKernel()
    {
        var modules = new INinjectModule[]
        {
            new NHibernateModule(),
            new ServiceModule(),
            new RepositoryModule()
        };
        return new StandardKernel(modules);
    }
}

NHibernateSessionFactoryProvider.cs

public class NhibernateSessionFactoryProvider : Provider<ISessionFactory>
{
    protected override ISessionFactory CreateInstance(IContext context)
    {
        var sessionFactory = new NhibernateSessionFactory();
        return sessionFactory.GetSessionFactory();
    } 
}

NHibernateSessionFactory.cs

public class NhibernateSessionFactory
{
    public ISessionFactory GetSessionFactory()
    {
        ISessionFactory fluentConfiguration = Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString(ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString)
            .Cache(c => c
            .UseQueryCache()
            .ProviderClass<HashtableCacheProvider>())
            .ShowSql())
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<AppointmentMap>()
            .Conventions.AddFromAssemblyOf<PrimaryKeyConvention>())
            .BuildSessionFactory();
        return fluentConfiguration;
    }
}

NHibernateModule.cs

public class NHibernateModule : NinjectModule
{
    public override void Load()
    {
        Bind<ISessionFactory>().ToProvider<NhibernateSessionFactoryProvider>().InSingletonScope();
        Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope();
    } 
}

RepositoryModule.cs

public class RepositoryModule : NinjectModule
{
    public override void Load()
    {
        Bind<IAuditRepository>().To<AuditRepository>();
        .
        .
        .
        Bind<IShotAdministeredRepository>().To<ShotAdministeredRepository>();
    } 
}

ServiceModule.cs

public class ServiceModule : NinjectModule
{
    public override void Load()
    {
        Bind<IAuditService>().To<AuditService>();
        .
        .
        .
        Bind<IShotService>().To<ShotService>();
    } 
}

NinjectInstanceProvider.cs

public class NinjectInstanceProvider : IInstanceProvider
{
    private Type serviceType;
    private IKernel kernel;

    public NinjectInstanceProvider(IKernel kernel, Type serviceType)
    {
        this.kernel = kernel;
        this.serviceType = serviceType;
    }

    public object GetInstance(InstanceContext instanceContext)
    {
        return this.GetInstance(instanceContext, null);
    }

    public object GetInstance(InstanceContext instanceContext, Message message)
    {
        //Create the instance with your IoC container of choice...here we're using Ninject
        return kernel.Get(this.serviceType);
    }

    public void ReleaseInstance(InstanceContext instanceContext, object instance)
    {
    }
}

NinjectBehaviorAttribute.cs

public class NinjectBehaviorAttribute : Attribute, IServiceBehavior
{
    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
    {
    }

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        Type serviceType = serviceDescription.ServiceType;
        IInstanceProvider instanceProvider = new NinjectInstanceProvider(new StandardKernel(), serviceType);

        foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
        {
            foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints)
            {
                DispatchRuntime dispatchRuntime = endpointDispatcher.DispatchRuntime;
                dispatchRuntime.InstanceProvider = instanceProvider;
            }
        }
    }

    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
    }
}

IAuditRepository.cs

public interface IAuditRepository : IRepository<Audit>
{
}

AuditRepository.cs

public class AuditRepository : Repository<Audit>, IAuditRepository
{
    public AuditRepository(ISession session) : base(session) { }
}

ShotRepository.cs

public class ShotRepository : Repository<Shot>, IShotRepository
{
    public ShotRepository(ISession session) : base(session) { }
}

ShotService.svc.cs

[NinjectBehaviorAttribute]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ShotService : IShotService
{
    #region Members
    private IAuditRepository _auditRepository;
    private IClientRepository _clientRepository;
    private IClinicRepository _clinicRepository;
    private IShotRepository _repository;
    private IShotAdministeredRepository _administeredRepository;
    private IShotCostRepository _costRepository;
    private IUserRepository _userRepository;
    #endregion

    #region Constructors
    public ShotService(IAuditRepository auditRepository, IClientRepository clientRepository, IClinicRepository clinicRepository, IShotRepository repository, IShotAdministeredRepository administeredRepository, IShotCostRepository costRepository, IUserRepository userRepository)
    {
        _auditRepository = auditRepository;
        _clientRepository = clientRepository;
        _clinicRepository = clinicRepository;
        _repository = repository;
        _administeredRepository = administeredRepository;
        _costRepository = costRepository;
        _userRepository = userRepository;
    }
    #endregion

    #region IShotService Members
    .
    .
    .
    public ListAdministeredShotsResponse LookupShotAdministered(LookupShotAdministeredRequest request)
    {
        ListAdministeredShotsResponse response = new ListAdministeredShotsResponse();
        try
        {
            UserService userService = new UserService(_userRepository, _auditRepository);
            User requestingUser = userService.Read(Convert.ToInt32(request.RequestingUserId));
            if (userService.HasPermission(requestingUser, Permissions.ScheduleAppointments))
            {
                ShotAdministeredService service = new ShotAdministeredService(_administeredRepository, _auditRepository);
                //Guts of method go here...irrelevant to current issue
            }
            else
            {
                throw new InvalidPermissionException("Requesting user does not have sufficient permissions to complete the request.");
            }
        }
        catch (Exception ex)
        {
            response.FailureReason = ex.Message;
        }
        return response;
    }
    .
    .
    .
    #endregion
}

I put a break point in CreateKernel(), it has not been hit. I also put a break point in Load() in NHibernateModule.cs, that break point has also not been hit. <– Correction…Cassini was “not responding” so I guess I wasn’t really debugging ALL of my code. I just did an End Task on Cassini and re-ran the debugger on my services…My break point in CreateKernel() was hit as well as my break point in Load(). My main issue still exists, but at least I know this code is being executed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:21:33+00:00Added an answer on June 2, 2026 at 11:21 pm

    You are using Ninject.Extensions.Wcf and you do an own integration into Wcf at the same time. There are two kernel instances involved one of which is configured and the other one not. You should decide which integration to use and configure that kernel properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a Silverlight (4.0) application that is calling to WCF-service. During 1st call
I'm hosting wcf services in console app for now, and sometimes I get this
Can we two WCF services where one service contract derives from another and have
In WCF services and a variety of other .NET apps, I understand that app.config
How to unit test WCF services? Any 3rd Party tools available?
I have 2 WCF services, (A and B), where A calls B. WCF Service
I have a wcf services projects and a second project for consuming these services
I have created several WCF services. In order to avoid adding service references in
I am developing WCF services with basicHttpBinding , these services should be accessible using
I have 2 WCF services now and I want to construct the WCF Service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.