Skip to content

Commit

Permalink
(#72) Minor cleanup
Browse files Browse the repository at this point in the history
* Spaces to tabs
* Removed unused 'using' statements
  • Loading branch information
par.dahlman committed Mar 16, 2016
1 parent 48a1e05 commit b8163fb
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 189 deletions.
95 changes: 45 additions & 50 deletions src/RawRabbit.DependencyInjection.Ninject/KernelExtension.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ninject;
using Ninject;
using RawRabbit.Common;
using RawRabbit.Configuration;
using RawRabbit.Context;

namespace RawRabbit.DependencyInjection.Ninject
{
public static class KernelExtension
{
public static IKernel RegisterRawRabbit<TMessageContext>(this IKernel kernel)
where TMessageContext : IMessageContext
{
kernel.Load(new RawRabbitModule<TMessageContext>());
return kernel;
}

public static IKernel RegisterRawRabbit(this IKernel kernel)
{
kernel.Load(new RawRabbitModule());
return kernel;
}

public static IKernel RegisterRawRabbit<TMessageContext>(this IKernel kernel, RawRabbitConfiguration configuration)
where TMessageContext : IMessageContext
{
kernel
.Bind<RawRabbitConfiguration>()
.ToConstant(configuration)
.InSingletonScope();

kernel.Load(new RawRabbitModule<TMessageContext>());
return kernel;
}

public static IKernel RegisterRawRabbit(this IKernel kernel, RawRabbitConfiguration configuration)
{
return RegisterRawRabbit<MessageContext>(kernel, configuration);
}

public static IKernel RegisterRawRabbit<TMessageContext>(this IKernel kernel, string connectionString)
where TMessageContext : IMessageContext
{
var config = ConnectionStringParser.Parse(connectionString);
return RegisterRawRabbit<TMessageContext>(kernel, config);
}

public static IKernel RegisterRawRabbit(this IKernel kernel, string connectionString)
{
return RegisterRawRabbit<MessageContext>(kernel, connectionString);
}

}
public static class KernelExtension
{
public static IKernel RegisterRawRabbit<TMessageContext>(this IKernel kernel)
where TMessageContext : IMessageContext
{
kernel.Load(new RawRabbitModule<TMessageContext>());
return kernel;
}

public static IKernel RegisterRawRabbit(this IKernel kernel)
{
kernel.Load(new RawRabbitModule());
return kernel;
}

public static IKernel RegisterRawRabbit<TMessageContext>(this IKernel kernel, RawRabbitConfiguration configuration)
where TMessageContext : IMessageContext
{
kernel
.Bind<RawRabbitConfiguration>()
.ToConstant(configuration)
.InSingletonScope();

kernel.Load(new RawRabbitModule<TMessageContext>());
return kernel;
}

public static IKernel RegisterRawRabbit(this IKernel kernel, RawRabbitConfiguration configuration)
{
return RegisterRawRabbit<MessageContext>(kernel, configuration);
}

public static IKernel RegisterRawRabbit<TMessageContext>(this IKernel kernel, string connectionString)
where TMessageContext : IMessageContext
{
var config = ConnectionStringParser.Parse(connectionString);
return RegisterRawRabbit<TMessageContext>(kernel, config);
}

public static IKernel RegisterRawRabbit(this IKernel kernel, string connectionString)
{
return RegisterRawRabbit<MessageContext>(kernel, connectionString);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
275 changes: 137 additions & 138 deletions src/RawRabbit.DependencyInjection.Ninject/RawRabbitModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
Expand All @@ -23,141 +22,141 @@

namespace RawRabbit.DependencyInjection.Ninject
{
public class RawRabbitModule : RawRabbitModule<MessageContext> { }

public class RawRabbitModule<TMessageContext> : NinjectModule where TMessageContext : IMessageContext
{
public override void Load()
{
Kernel
.Bind<ISubscriber<TMessageContext>>()
.To<Subscriber<TMessageContext>>()
.InSingletonScope();

Kernel
.Bind<IPublisher>()
.To<Publisher<TMessageContext>>()
.InSingletonScope();

Kernel
.Bind<IResponder<TMessageContext>>()
.To<Responder<TMessageContext>>()
.InSingletonScope();

Kernel
.Bind<IRequester>()
.To<Requester<TMessageContext>>()
.InSingletonScope()
.WithConstructorArgument("requestTimeout", (context) =>
context.Kernel.Get<RawRabbitConfiguration>().RequestTimeout);

Kernel
.Bind<IMessageContextProvider<TMessageContext>>()
.To<MessageContextProvider<TMessageContext>>()
.InSingletonScope()
.WithConstructorArgument("createContextAsync", (Func<Task<TMessageContext>>) null);

Kernel
.Bind<IContextEnhancer>()
.To<ContextEnhancer>()
.InSingletonScope();

Kernel
.Bind<ITopologyProvider>()
.To<TopologyProvider>()
.InSingletonScope();

Kernel
.Bind<IConnectionFactory>()
.ToMethod(context =>
{
var cfg = context.Kernel.Get<RawRabbitConfiguration>();
return new ConnectionFactory
{
VirtualHost = cfg.VirtualHost,
UserName = cfg.Username,
Password = cfg.Password,
Port = cfg.Port,
HostName = cfg.Hostnames.FirstOrDefault() ?? string.Empty,
AutomaticRecoveryEnabled = cfg.AutomaticRecovery,
TopologyRecoveryEnabled = cfg.TopologyRecovery,
NetworkRecoveryInterval = cfg.RecoveryInterval,
ClientProperties = context.Kernel.Get<IClientPropertyProvider>().GetClientProperties(cfg),
Ssl = cfg.Ssl
};
})
.InSingletonScope();

Kernel
.Bind<IClientPropertyProvider>()
.To<ClientPropertyProvider>()
.InSingletonScope();

Kernel
.Bind<ILoggerFactory>()
.To<LoggerFactory>()
.InSingletonScope();

Kernel
.Bind<IMessageSerializer>()
.To<JsonMessageSerializer>()
.InSingletonScope()
.WithConstructorArgument("config", (Action<JsonSerializer>) null);

Kernel
.Bind<IConsumerFactory>()
.To<EventingBasicConsumerFactory>()
.InSingletonScope();

Kernel
.Bind<IErrorHandlingStrategy>()
.To<DefaultStrategy>()
.InSingletonScope();

Kernel
.Bind<IBasicPropertiesProvider>()
.To<BasicPropertiesProvider>()
.InSingletonScope();

Kernel
.Bind<IChannelFactory>()
.To<ChannelFactory>()
.InSingletonScope();

Kernel
.Bind<ChannelFactoryConfiguration>()
.ToConstant(ChannelFactoryConfiguration.Default)
.InSingletonScope();

Kernel
.Bind<IConfigurationEvaluator>()
.To<ConfigurationEvaluator>()
.InSingletonScope();

Kernel
.Bind<IPublishAcknowledger>()
.To<PublishAcknowledger>()
.InSingletonScope()
.WithConstructorArgument("publishTimeout",
context => context.Kernel.Get<RawRabbitConfiguration>().PublishConfirmTimeout);

Kernel
.Bind<INamingConventions>()
.To<NamingConventions>()
.InSingletonScope();

Kernel
.Bind<IBusClient<TMessageContext>>()
.To<BaseBusClient<TMessageContext>>()
.InSingletonScope();

if (typeof (TMessageContext) == typeof (MessageContext))
{
Kernel
.Bind<IBusClient>()
.To<BusClient>()
.InSingletonScope();
}
}
}
public class RawRabbitModule : RawRabbitModule<MessageContext> { }

public class RawRabbitModule<TMessageContext> : NinjectModule where TMessageContext : IMessageContext
{
public override void Load()
{
Kernel
.Bind<ISubscriber<TMessageContext>>()
.To<Subscriber<TMessageContext>>()
.InSingletonScope();

Kernel
.Bind<IPublisher>()
.To<Publisher<TMessageContext>>()
.InSingletonScope();

Kernel
.Bind<IResponder<TMessageContext>>()
.To<Responder<TMessageContext>>()
.InSingletonScope();

Kernel
.Bind<IRequester>()
.To<Requester<TMessageContext>>()
.InSingletonScope()
.WithConstructorArgument("requestTimeout", (context) =>
context.Kernel.Get<RawRabbitConfiguration>().RequestTimeout);

Kernel
.Bind<IMessageContextProvider<TMessageContext>>()
.To<MessageContextProvider<TMessageContext>>()
.InSingletonScope()
.WithConstructorArgument("createContextAsync", (Func<Task<TMessageContext>>)null);

Kernel
.Bind<IContextEnhancer>()
.To<ContextEnhancer>()
.InSingletonScope();

Kernel
.Bind<ITopologyProvider>()
.To<TopologyProvider>()
.InSingletonScope();

Kernel
.Bind<IConnectionFactory>()
.ToMethod(context =>
{
var cfg = context.Kernel.Get<RawRabbitConfiguration>();
return new ConnectionFactory
{
VirtualHost = cfg.VirtualHost,
UserName = cfg.Username,
Password = cfg.Password,
Port = cfg.Port,
HostName = cfg.Hostnames.FirstOrDefault() ?? string.Empty,
AutomaticRecoveryEnabled = cfg.AutomaticRecovery,
TopologyRecoveryEnabled = cfg.TopologyRecovery,
NetworkRecoveryInterval = cfg.RecoveryInterval,
ClientProperties = context.Kernel.Get<IClientPropertyProvider>().GetClientProperties(cfg),
Ssl = cfg.Ssl
};
})
.InSingletonScope();

Kernel
.Bind<IClientPropertyProvider>()
.To<ClientPropertyProvider>()
.InSingletonScope();

Kernel
.Bind<ILoggerFactory>()
.To<LoggerFactory>()
.InSingletonScope();

Kernel
.Bind<IMessageSerializer>()
.To<JsonMessageSerializer>()
.InSingletonScope()
.WithConstructorArgument("config", (Action<JsonSerializer>)null);

Kernel
.Bind<IConsumerFactory>()
.To<EventingBasicConsumerFactory>()
.InSingletonScope();

Kernel
.Bind<IErrorHandlingStrategy>()
.To<DefaultStrategy>()
.InSingletonScope();

Kernel
.Bind<IBasicPropertiesProvider>()
.To<BasicPropertiesProvider>()
.InSingletonScope();

Kernel
.Bind<IChannelFactory>()
.To<ChannelFactory>()
.InSingletonScope();

Kernel
.Bind<ChannelFactoryConfiguration>()
.ToConstant(ChannelFactoryConfiguration.Default)
.InSingletonScope();

Kernel
.Bind<IConfigurationEvaluator>()
.To<ConfigurationEvaluator>()
.InSingletonScope();

Kernel
.Bind<IPublishAcknowledger>()
.To<PublishAcknowledger>()
.InSingletonScope()
.WithConstructorArgument("publishTimeout",
context => context.Kernel.Get<RawRabbitConfiguration>().PublishConfirmTimeout);

Kernel
.Bind<INamingConventions>()
.To<NamingConventions>()
.InSingletonScope();

Kernel
.Bind<IBusClient<TMessageContext>>()
.To<BaseBusClient<TMessageContext>>()
.InSingletonScope();

if (typeof(TMessageContext) == typeof(MessageContext))
{
Kernel
.Bind<IBusClient>()
.To<BusClient>()
.InSingletonScope();
}
}
}
}

0 comments on commit b8163fb

Please sign in to comment.