# StructureMap

The following example shows how to configure a simple StructureMap container, and include the bus in the container. The two bus interfaces, IBus and IBusControl, are included.

A sample project for the container registration code is available on GitHub (opens new window).

TIP

Consumers should not typically depend upon IBus or IBusControl. A consumer should use the ConsumeContext instead, which has all of the same methods as IBus, but is scoped to the receive endpoint. This ensures that messages can be tracked between consumers, and are sent from the proper address.

public static void Main(string[] args)
{
   var container = new Container(cfg =>
   {
       cfg.AddMassTransit(x =>
       {
           // add a specific consumer
           x.AddConsumer<UpdateCustomerAddressConsumer>();

           // add all consumers in the specified assembly
           x.AddConsumers(Assembly.GetExecutingAssembly());

           // add consumers by type
           x.AddConsumers(typeof(ConsumerOne), typeof(ConsumerTwo));

           // add the bus to the container, may need to create Local function
           x.UsingRabbitMq((context, cfg) =>
           {
               cfg.Host("localhost/");

               cfg.ReceiveEndpoint("customer_update", ec =>
               {
                   // Configure a single consumer
                   ec.ConfigureConsumer<UpdateCustomerConsumer>(context);

                   // configure all consumers
                   ec.ConfigureConsumers(context);

                   // configure consumer by type
                   ec.ConfigureConsumer(typeof(ConsumerOne), context);
               });

               // or, configure the endpoints by convention
               cfg.ConfigureEndpoints(context);
           });
       });
   });

   IBusControl busControl = container.GetInstance<IBusControl>();
   busControl.Start();
}