0

これは私がこれまでに持っているものです。IBus インジェクション/作成ポイント (パブリッシャー) を実装するコンセプト/場所に行き詰まっています。パブリッシャーの機能をすべてプロジェクト内に保持し、別のサービスを作成しないようにしていました。

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

これは私の最初のパスなので、提案やベストプラクティスのアドバイスをお待ちしています:-)

やり残したこと:

  • キュー名と ?
  • 接続管理を処理するメッセージ ハンドラーを作成しますか?
  • アプリの起動時にパブリッシャーを作成し、?

EasyNetQ 内部 IoC を置き換える EasyNetQ Wrapper、Ninject の置き換え:

  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;
        });
    }        

パブリッシャー クラス:

  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);
    }
 }
4

0 に答える 0