# Microsoft Dependency Injection

MassTransit fully supports the Microsoft Dependency Injection framework used by ASP.NET Core. In fact, most of the container-based examples in the documentation use the Microsoft container as it is the most popular.

The container section includes examples and usage details, refer to that section for more details.

Uses MassTransit.RabbitMQ (opens new window) MassTransit.Extensions.DependencyInjection (opens new window)

namespace MicrosoftContainer
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using ContainerConsumers;
    using MassTransit;
    using Microsoft.Extensions.DependencyInjection;

    public class Program
        public static async Task Main()
            var services = new ServiceCollection();

            services.AddMassTransit(x =>


                x.UsingRabbitMq((context, cfg) => cfg.ConfigureEndpoints(context));

            var provider = services.BuildServiceProvider();

            var busControl = provider.GetRequiredService<IBusControl>();

            await busControl.StartAsync(new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
                Console.WriteLine("Press enter to exit");

                await Task.Run(() => Console.ReadLine());
                await busControl.StopAsync();

# ASP.NET Core

Using MassTransit with ASP.NET Core is details in the configuration section.