public static IServiceCollection AddBasePatLiteServices(this IServiceCollection services, IConfiguration configuration) { var senderSettings = new PatSenderSettings(); var subscriberConfiguration = new SubscriberConfiguration(); var dataProtectionConfiguration = new DataProtectionConfiguration(); configuration.GetSection("PatLite:Sender").Bind(senderSettings); configuration.GetSection("PatLite:Subscriber").Bind(subscriberConfiguration); configuration.GetSection("DataProtection").Bind(dataProtectionConfiguration); services.AddPatLite(subscriberConfiguration) .AddTransient <IEncryptedMessagePublisher>( provider => new EncryptedMessagePublisher( provider.GetRequiredService <IMessageSender>(), dataProtectionConfiguration, provider.GetRequiredService <MessageProperties>())) .AddPatSenderNetCoreLogAdapter() .AddTransient <IMessageSender, MessageSender>() .AddSingleton <IMessageGenerator, MessageGenerator>() .AddSingleton <MessageProperties, MessageProperties>() .AddSingleton(senderSettings) .AddSingleton <ICorrelationIdProvider, NewCorrelationIdProvider>() .AddTransient <IMessagePublisher>(provider => new MessagePublisher( provider.GetRequiredService <IMessageSender>(), provider.GetRequiredService <IMessageGenerator>(), GetAnnotatedMessageProperties(provider) )); return(services); }
private static IContainer InitialiseIoC() { var connection = "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOURKEY"; var topicName = "pat"; var sender = new PatSenderSettings { TopicName = topicName, PrimaryConnection = connection, UseDevelopmentTopic = false }; InitLogger(); var container = new Container(x => { x.Scan(scanner => { scanner.WithDefaultConventions(); scanner.AssemblyContainingType <IMessagePublisher>(); }); x.For <ICorrelationIdProvider>().Use(new LiteralCorrelationIdProvider($"{Guid.NewGuid()}")); x.For <PatSenderSettings>().Use(sender); x.For(typeof(IPatSenderLog <>)).Use(typeof(PatSenderLog4NetAdapter <>)); x.For <ILog>().Use(context => LogManager.GetLogger(context.ParentType)); }); return(container); }
public void PatSenderSettings_DoesNotAppendMachineNameToTopic_WhenNotInDevelopmentMode() { var configuration = new PatSenderSettings { TopicName = "test", UseDevelopmentTopic = false }; Assert.Equal("test", configuration.EffectiveTopicName); }
public void PatSenderSettings_DoesAppendMachineNameToTopic_WhenInDevelopmentMode() { var configuration = new PatSenderSettings { TopicName = "test", UseDevelopmentTopic = true }; Assert.Equal("test" + Environment.MachineName, configuration.EffectiveTopicName); }
public static IContainer Initialize(IConfigurationRoot configuration) { var senderSettings = new PatSenderSettings(); configuration.GetSection("PatLite:Sender").Bind(senderSettings); var subscriberConfiguration = new SubscriberConfiguration(); configuration.GetSection("PatLite:Subscriber").Bind(subscriberConfiguration); var statisticsConfiguration = new StatisticsReporterConfiguration(); configuration.GetSection("StatsD").Bind(statisticsConfiguration); var dataProtectionConfiguration = new DataProtectionConfiguration(); configuration.GetSection("DataProtection").Bind(dataProtectionConfiguration); var statsReporter = new StatisticsReporter(statisticsConfiguration); var loggerName = "IntegrationLogger"; Logging.InitLogger(loggerName); var container = new Container(x => { x.AddRegistry(new PatLiteRegistry(new PatLiteOptions { SubscriberConfiguration = subscriberConfiguration, RegisterDefaultLoggerWithName = "Pat" })); }); container.Configure(x => { x.Scan(scanner => { scanner.WithDefaultConventions(); scanner.AssemblyContainingType <IMessagePublisher>(); }); x.For <IStatisticsReporter>().Use(statsReporter); x.For <ICorrelationIdProvider>().Use(new LiteralCorrelationIdProvider(Guid.NewGuid().ToString())); x.For <IMessageDeserialiser>().Use(ctx => ctx.GetInstance <MessageContext>().MessageEncrypted ? new EncryptedMessageDeserialiser(ctx.GetInstance <DataProtectionConfiguration>()) : (IMessageDeserialiser) new NewtonsoftMessageDeserialiser()); x.For <PatSenderSettings>().Use(senderSettings); x.For <MessageReceivedNotifier <TestEvent> >().Use(new MessageReceivedNotifier <TestEvent>()); x.For <DataProtectionConfiguration>().Use(dataProtectionConfiguration); x.For <ILog>().Use(LogManager.GetLogger(loggerName, loggerName)); x.For <ILoggerFactory>().Use(context => new LoggerFactory()); }); return(container); }
public static IServiceCollection Initialize(IConfigurationRoot configuration) { var senderSettings = new PatSenderSettings(); configuration.GetSection("PatLite:Sender").Bind(senderSettings); var subscriberConfiguration = new SubscriberConfiguration(); configuration.GetSection("PatLite:Subscriber").Bind(subscriberConfiguration); var statisticsConfiguration = new StatisticsReporterConfiguration(); configuration.GetSection("StatsD").Bind(statisticsConfiguration); var dataProtectionConfiguration = new DataProtectionConfiguration(); configuration.GetSection("DataProtection").Bind(dataProtectionConfiguration); var loggerName = "IntegrationLogger-DotNetIoC"; Logging.InitLogger(loggerName); var serviceCollection = new ServiceCollection() .AddSingleton(senderSettings) .AddSingleton(subscriberConfiguration) .AddSingleton(statisticsConfiguration) .AddSingleton(dataProtectionConfiguration) .AddSingleton <IMessageGenerator, MessageGenerator>() .AddSingleton <MessageReceivedNotifier <TestEvent> >() .AddTransient <IEncryptedMessagePublisher>( provider => new EncryptedMessagePublisher( provider.GetRequiredService <IMessageSender>(), provider.GetRequiredService <DataProtectionConfiguration>(), new MessageProperties(Guid.NewGuid().ToString()))) .AddTransient <IMessagePublisher>( provider => new MessagePublisher( provider.GetRequiredService <IMessageSender>(), provider.GetRequiredService <IMessageGenerator>(), new MessageProperties(Guid.NewGuid().ToString()))) .AddTransient <IMessageSender, MessageSender>() .AddTransient <IStatisticsReporter, StatisticsReporter>() .AddLogging(b => b.AddDebug()) .AddTransient <ILog>(s => LogManager.GetLogger(loggerName, loggerName)) .AddPatLite(new PatLiteOptions { MessageDeserialiser = provider => provider.GetService <MessageContext>().MessageEncrypted ? new EncryptedMessageDeserialiser(provider.GetService <DataProtectionConfiguration>()) : (IMessageDeserialiser) new NewtonsoftMessageDeserialiser(), SubscriberConfiguration = subscriberConfiguration }) .AddHandlersFromAssemblyContainingType <DotNetIoC>(); return(serviceCollection); }
private static ServiceProvider InitialiseIoC() { var connection = "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YOURKEY"; var topicName = "pat"; var settings = new PatSenderSettings { TopicName = topicName, PrimaryConnection = connection, UseDevelopmentTopic = false }; var serviceProvider = new ServiceCollection() .AddLogging(b => b.AddConsole()) .AddPatSender(settings) .BuildServiceProvider(); return(serviceProvider); }
private static IServiceCollection AddPatSender(this IServiceCollection services, PatSenderSettings settings) => services .AddPatSenderNetCoreLogAdapter() .AddSingleton(settings) .AddTransient <IMessagePublisher, MessagePublisher>() .AddTransient <IMessageSender, MessageSender>() .AddTransient <IMessageGenerator, MessageGenerator>() .AddTransient(s => new MessageProperties(new LiteralCorrelationIdProvider($"{Guid.NewGuid()}")));
public void PatSenderSettings_EntersDevelopmentModeByDefault() { var configuration = new PatSenderSettings(); Assert.True(configuration.UseDevelopmentTopic); }