0

This is what I have thus far. I'm stuck on the concept/where to implement the IBus injection/creation point (the publisher). I was trying to keep the publisher functionality all within the project and not create a separate service for it.

   bus = RabbitHutch.CreateBus("host=localhost", x => x.Register<IEasyNetQLogger>(_ => logger));

This is my first pass at this so I'm open to suggestions and best practice advice :-)

Things left to do:

  • create a rabbitmq config file with proper settings defining queue name and ?
  • create a message handler that takes care of connection management that is?
  • create the publisher at app start up, dispose properly when ?

EasyNetQ Wrapper to replace EasyNetQ internal IoC, Ninject replacement:

  public class NinjectContainerWrapper: IContainer, IDisposable
  {

    public NinjectContainerWrapper()
    {

    }

    //ninject container/kernal? here
    //private readonly ISomeNinjectInterface container;
    public TService Resolve<TService>() where TService : class
    {
        throw new NotImplementedException();
    }

    public IServiceRegister Register<TService, TImplementation>()
        where TService : class
        where TImplementation : class, TService
    {
        throw new NotImplementedException();
    }

    public IServiceRegister Register<TService>(Func<EasyNetQ.IServiceProvider, TService> serviceCreator) where TService : class
    {
        throw new NotImplementedException();
    }

    public void Dispose()
    {
        throw new NotImplementedException();
    }
  }

NinjectWebCommon.cs

  private static void RegisterServices(IKernel kernel)
  {
        kernel.Bind<IAppSettings>().To<AppSettings>();
        kernel.Bind<IDmpeService>().To<DmpeService>();
        kernel.Bind<IPublisher>().To<DmpePublisher>();
        kernel.Bind<IEasyNetQLogger>().To<GdmEasyNetQLogger>();
        kernel.Bind<ILoggingService>().ToMethod(x =>
        {
            var scope = x.Request.ParentRequest.Service.FullName;
            var log = (ILoggingService)LogManager.GetLogger(scope, typeof(LoggingService));
            return log;
        });
    }        

the publisher class:

  public class DmpePublisher: IPublisher
  {
    private readonly IEasyNetQLogger _logger;
    private readonly IAppSettings _appSettings;
    private readonly IBus bus = null;

    public DmpePublisher(IEasyNetQLogger logger, IAppSettings appSettings)
    {
        this._logger = logger;
        this._appSettings = appSettings;

        // register our alternative container factory
        RabbitHutch.SetContainerFactory(() =>
        {
            var ninjectContainer = new NinjectContainerWrapper();

            // wrap it in our implementation of EasyNetQ.IContainer
            //return new NinjectContainerWrapper(ninjectContainer);
        });

         bus = RabbitHutch.CreateBus("host=localhost", x => x.Register<IEasyNetQLogger>(_ => logger));
    }

    public void PublishMessage(Messages.IMessage message)
    {
        throw new NotImplementedException();
        //log post
        //_logger.InfoWrite("Publishing message: {0}", message);
    }
 }
MarredCheese
  • 17,541
  • 8
  • 92
  • 91
Will Lopez
  • 2,089
  • 3
  • 40
  • 64
  • You dont need to implement the wrapper for NInject, you can use EasyNetQ.DI.Ninject package. When it comes to IBus you need to call Dispose on it when finihed. I would recommend you to create a wrapper (service) that will have IBus creation in it. Then it will give you a chance to Dispose IBus when finished. EasyNetQ recommend to have one IBus for the app so you can register the wrapper as single instance service. – Piotr W May 18 '15 at 11:58
  • Thank you @PiotrW! I will try that this weekend. – Will Lopez May 22 '15 at 19:46

0 Answers0