1

I am currently setting up a simple MVC application that is structured as an Onion Architecture. For simplicity's sake, assume that I have the following projects (disregarding the business and database layers, at the moment):

  • Sample.Web - This is the ASP.NET MVC Application
  • Sample.Application - This contains the application services.
  • Sample.Infrastructure - This contains the infrastructure services.

For now, I am using Ninject (although that will likely change). So, with Ninject MVC, I am registering the Application and Infrastructure services at startup, using the Sample.Web to act as the composition root. Application services from Sample.Application are injected into the controllers, and that is straightforward enough and working well.

Where I am having issues, though, is determining how to properly initialize MassTransit, in the equation. Ideally, I want to have a generic interface to wrap the ConsumeContext instance and allow for me to set up the events. I do not seem to be able to fully set up the instance from within Sample.Infrastructure, as the infrastructure does not/should not know what the events are. I would assume that the consumer classes should exist in Sample.Application, and I do not think that the infrastructure should have a dependency on knowing the consumers.

On startup, System.Web will load the NinjectModule from each System.Application and System.Infrastructure. Does that mean that System.Web should have explicit knowledge of the consumer classes, so that it can configure the IBusControl instance, or is there a more elegant solution?

Right now, the path that I think I am going down is that Sample.Web will load the NinjectModule instances, as it does, and then I will configure the ConsumeContext from Application_Start, after I have explicitly loaded the consumers. However, that would mean that I would have to rebuild/redeploy Sample.Web if I ever add consumers, which is less than ideal and is the root of my concerns. Assuming that consumers are defined within Sample.Application, and all event publications and subscriptions exist within Sample.Application, having to touch either Sample.Web or Sample.Infrastructure to add a consumer is code smell.

Many thanks, in advance.

Edit

As always, after hitting submit, something else comes to mind. I think that one possible solution may be to have Sample.Web as Sample.Application for the known endpoints. Since all events will be published and subscribed from Sample.Application, it would make some sense to have Sample.Web create the actual instance in Sample.Infrastructure and compose the endpoints from what it learns from Sample.Application.

Am definitely open to other solutions, though.

Joseph Ferris
  • 12,576
  • 3
  • 46
  • 72
  • Just a slappy comment, but why do people insist on using NInject still? – Chris Patterson Jul 06 '16 at 16:06
  • Rapid proof of concept. No insistence on usage, as mentioned in the original post. The intent is that I will use SimpleInjector, which is my current DI framework of choice. But, since MassTransit is new to me, I am using a DI framework that I had used in the past for which they had example code. – Joseph Ferris Jul 06 '16 at 18:01
  • @ChrisPatterson what's wrong with Ninject? – Dave Thieben Jul 07 '16 at 13:59
  • @davethieben Its major issue is its performance. Convention-wise, I have no issues with it. Personally, I've only moved to SimpleInjector because it is incredibly fast, especially once you have Interceptors in play. – Joseph Ferris Jul 08 '16 at 05:28
  • I am not familiar with Ninject, but MT has some IoC adapters and we use Autofac successfully without any issue. Not sure about `ConsumeContext`, we just scan given list of assemblies and register all implementations of `IConsumer`, then we call `LoadConsumers` provided by MT Autofac adapter and register `IBusControl`. And everything just works. – Alexey Zimarev Jul 16 '16 at 10:18

0 Answers0