Skip to content

Commit

Permalink
(#219) Change place of CurrentLogger registration
Browse files Browse the repository at this point in the history
There are numerous ways to create a bus client, and at some point
the call to sett CurrentLogger needs to be made. We know that the
ConnectionFactory will allways be a singleton and always be resolved
when the client is resolved. It might be hacky, but it works
  • Loading branch information
pardahlman committed May 7, 2017
1 parent 4306167 commit 9d7834d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion sample/RawRabbit.ConsoleApp.Sample/Program.cs
Expand Up @@ -2,10 +2,12 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RawRabbit.Configuration;
using RawRabbit.Enrichers.GlobalExecutionId;
using RawRabbit.Enrichers.MessageContext;
using RawRabbit.Enrichers.MessageContext.Context;
using RawRabbit.Logging;
using RawRabbit.Messages.Sample;
using RawRabbit.vNext;
using RawRabbit.vNext.Pipe;
Expand All @@ -32,7 +34,9 @@ public static async Task RunAsync()
.Get<RawRabbitConfiguration>(),
Plugins = p => p
.UseGlobalExecutionId()
.UseMessageContext<MessageContext>()
.UseMessageContext<MessageContext>(),
DependencyInjection = ioc => ioc
.AddSingleton<ILoggerFactory>(provider => new LoggerFactory(s => new ConsoleLogger(LogLevel.Debug, s)))
});

await _client.SubscribeAsync<ValuesRequested, MessageContext>((requested, ctx) => ServeValuesAsync(requested, ctx));
Expand Down
2 changes: 1 addition & 1 deletion src/RawRabbit.vNext/AddRawRabbitExtension.cs
Expand Up @@ -9,9 +9,9 @@ public static class AddRawRabbitExtension
{
public static IServiceCollection AddRawRabbit(this IServiceCollection collection, RawRabbitOptions options = null)
{
options?.DependencyInjection?.Invoke(collection);
var adapter = new ServiceCollectionAdapter(collection);
adapter.AddRawRabbit(options);
options?.DependencyInjection?.Invoke(collection);
return collection;
}
}
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using System.Runtime.Serialization.Formatters;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
Expand Down Expand Up @@ -36,6 +35,7 @@ public static IDependecyRegister AddRawRabbit(this IDependecyRegister register,
.AddSingleton(options?.ClientConfiguration ?? RawRabbitConfiguration.Local)
.AddSingleton<IConnectionFactory, ConnectionFactory>(provider =>
{
LogManager.CurrentFactory = provider.GetService<ILoggerFactory>();
var cfg = provider.GetService<RawRabbitConfiguration>();
return new ConnectionFactory
{
Expand Down
1 change: 0 additions & 1 deletion src/RawRabbit/Instantiation/RawRabbitFactory.cs
Expand Up @@ -28,7 +28,6 @@ public static InstanceFactory CreateInstanceFactory(RawRabbitOptions options, ID
{
register.AddRawRabbit(options);
var resolver = resolverFunc(register);
LogManager.CurrentFactory = resolver.GetService<ILoggerFactory>();
return new InstanceFactory(resolver);
}
}
Expand Down

0 comments on commit 9d7834d

Please sign in to comment.