Skip to content

Commit

Permalink
Channel factory now resolving channel instances through IoC, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesgoeleven committed Mar 4, 2014
1 parent 1db5ccc commit 9e48e3d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/NServiceBus.Core/Gateway/Channels/ChannelFactory.cs
Expand Up @@ -14,12 +14,16 @@ public class ChannelFactory : IChannelFactory
{
public IChannelReceiver GetReceiver(string channelType)
{
return Activator.CreateInstance(receivers[channelType.ToLower()]) as IChannelReceiver;
var receiver = receivers[channelType.ToLower()];

return Configure.Instance.Builder.Build(receiver) as IChannelReceiver;
}

public IChannelSender GetSender(string channelType)
{
return Activator.CreateInstance(senders[channelType.ToLower()]) as IChannelSender;
var sender = senders[channelType.ToLower()];

return Configure.Instance.Builder.Build(sender) as IChannelSender;
}


Expand All @@ -31,6 +35,11 @@ public void RegisterReceiver(Type receiver)
public void RegisterReceiver(Type receiver, string type)
{
receivers.Add(type.ToLower(), receiver);

if (!Configure.HasComponent(receiver))
{
Configure.Component(receiver, DependencyLifecycle.InstancePerCall);
}
}


Expand All @@ -51,6 +60,11 @@ public void RegisterSender(Type sender)
public void RegisterSender(Type sender, string type)
{
senders.Add(type.ToLower(), sender);

if (!Configure.HasComponent(sender))
{
Configure.Component(sender, DependencyLifecycle.InstancePerCall);
}
}

readonly IDictionary<string, Type> receivers = new Dictionary<string, Type>();
Expand Down

2 comments on commit 9e48e3d

@johnsimons
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to get rid of our dependency on statics, is there a different way to fix this without using statics?

@yvesgoeleven
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an alternative to Configure.HasComponent / Configure.Component? IBuilder can be injected.

Currently ChannelFactory is not resolved through the container either, so that would need to change as well than.

Please sign in to comment.