public static void AddRabbitMq(this ContainerBuilder builder) { builder.Register(context => { var configuration = context.Resolve <IConfiguration>(); var options = configuration.GetOptions <RabbitMqOptions>("rabbitMq"); return(options); }).SingleInstance(); builder.Register(context => { var configuration = context.Resolve <IConfiguration>(); var options = configuration.GetOptions <RawRabbitConfiguration>("rabbitMq"); return(options); }).SingleInstance(); var assembly = Assembly.GetCallingAssembly(); builder.RegisterAssemblyTypes(assembly) .AsClosedTypesOf(typeof(IEventHandler <>)) .InstancePerDependency(); builder.RegisterAssemblyTypes(assembly) .AsClosedTypesOf(typeof(ICommandHandler <>)) .InstancePerDependency(); builder.RegisterType <Handler>().As <IHandler>() .InstancePerDependency(); builder.RegisterType <BusPublisher>().As <IBusPublisher>() .InstancePerDependency(); builder.RegisterInstance(DefaultTracer.Create()).As <ITracer>().SingleInstance() .PreserveExistingDefaults(); ConfigureBus(builder); }
public static IServiceCollection AddJaeger(this IServiceCollection serviceCollection, JaegerOptions options) { if (Interlocked.Exchange(ref _initialized, 1) == 1) { return(serviceCollection); } serviceCollection.AddSingleton(options); if (!options.Enabled) { var defaultTracer = DefaultTracer.Create(); serviceCollection.AddSingleton(defaultTracer); return(serviceCollection); } if (options.ExcludePaths is { })
public static void AddMessageService(this ContainerBuilder builder, IServiceCollection collection) { var conf = collection.BuildServiceProvider().GetService <IConfiguration>(); var optionsrawRabbitmq = conf.GetOptions <RawRabbitConfiguration>("rabbitMq"); var optionsRabbitmq = conf.GetOptions <RabbitMqOptions>("rabbitMq"); useRabbitMQ = optionsRabbitmq.Enable; var optionsAzureBusmq = conf.GetOptions <AzureBusOptions>("azureServiceBus"); useAzureServiceBus = optionsAzureBusmq.Enable; builder.Register(context => { return(optionsRabbitmq); }).SingleInstance(); builder.Register(context => { return(optionsAzureBusmq); }).SingleInstance(); builder.Register(context => { return(optionsrawRabbitmq); }).SingleInstance(); if ((useRabbitMQ && useAzureServiceBus) || (!useRabbitMQ && !useAzureServiceBus)) { throw new ApplicationException("Only one bus configuration need to be set up"); } var assembly = Assembly.GetCallingAssembly(); builder.RegisterAssemblyTypes(assembly) .AsClosedTypesOf(typeof(IEventHandler <>)) .InstancePerDependency(); builder.RegisterAssemblyTypes(assembly) .AsClosedTypesOf(typeof(ICommandHandler <>)) .InstancePerDependency(); builder.RegisterType <Handler>().As <IHandler>() .InstancePerDependency(); builder.RegisterInstance(DefaultTracer.Create()).As <ITracer>().SingleInstance() .PreserveExistingDefaults(); ConfigureBus(builder); }
public static IServiceCollection AddJaeger(this IServiceCollection services) { if (_initialized) { return(services); } _initialized = true; var options = GetJaegerOptions(services); if (!options.Enabled) { var defaultTracer = DefaultTracer.Create(); services.AddSingleton(defaultTracer); return(services); } services.AddSingleton <ITracer>(sp => { var loggerFactory = sp.GetRequiredService <ILoggerFactory>(); var reporter = new RemoteReporter .Builder() .WithSender(new UdpSender(options.UdpHost, options.UdpPort, options.MaxPacketSize)) .WithLoggerFactory(loggerFactory) .Build(); var sampler = GetSampler(options); var tracer = new Tracer .Builder(options.ServiceName) .WithReporter(reporter) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); return(services); }