Search code examples
c#.netdependency-injectionninjectremoting

using ninject with a remoting server


I have a class Server that implements interface IServer that is accessible using .net remoting (i have no chioce on the matter JICYAW).

internally this server uses other classes to implement logic and data access.

this server class has constructor injected dependencies that it needs to do its job.

when a client calls in (per call) the remoting framework will instatiate a Server instance using a parameterless constructor and not (of course) using Ninject.

how can i get Ninject to be the one in charge for new'ing up the class ?

i have seen this similar SO question but this isnt relevant for Ninject.

thanks for your help


Solution

  • You can create a service facade that will be called by the client. This facade will internally call your container to resolve the real service. For instance:

    public class ServiceFacade : IService
    {
        private readonly IService service;
    
        // default constructor
        public ServiceFacade()
        {
            this.service = YourContainer.Current.Resolve<IService>();
        }
    
        void IService.ServiceOperation()
        {
            this.service.ServiceOperation();
        }
    }