Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2010 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/574649 to your computer and use it in GitHub Desktop.
Save anonymous/574649 to your computer and use it in GitHub Desktop.
using System;
using System.Configuration;
using NServiceBus.Config;
using NServiceBus.Config.ConfigurationSource;
namespace NServiceBus
{
public class UserConfigurationSource : IConfigurationSource
{
readonly Action<UnicastBusConfig> UnicastCallback;
readonly Action<MsmqTransportConfig> MsmqTransportCallback;
public UserConfigurationSource()
: this(null, null)
{
}
public UserConfigurationSource(Action<UnicastBusConfig> unicastCallback)
: this(unicastCallback, null)
{
}
public UserConfigurationSource(Action<MsmqTransportConfig> msmqTransportCallback)
: this(null, msmqTransportCallback)
{
}
public UserConfigurationSource(Action<UnicastBusConfig> unicastCallback, Action<MsmqTransportConfig> msmqTransportCallback)
{
this.UnicastCallback = unicastCallback;
this.MsmqTransportCallback = msmqTransportCallback;
}
public T GetConfiguration<T>() where T : class
{
if (typeof(T) == typeof(MsmqSubscriptionStorageConfig))
return ConfigurationManager.GetSection(typeof(T).Name) as T;
if (typeof(T) == typeof(DBSubscriptionStorageConfig))
return ConfigurationManager.GetSection(typeof(T).Name) as T;
if (typeof(T) == typeof(MsmqTransportConfig) && MsmqTransportCallback != null)
return MsmqTransportConfiguration() as T;
if (typeof(T) == typeof(UnicastBusConfig) && UnicastCallback != null)
return UnicastBusConfiguration() as T;
return ConfigurationManager.GetSection(typeof(T).Name) as T;
}
private UnicastBusConfig UnicastBusConfiguration()
{
var config = new UnicastBusConfig();
UnicastCallback(config);
return config;
}
private MsmqTransportConfig MsmqTransportConfiguration()
{
var config = new MsmqTransportConfig();
MsmqTransportCallback(config);
return config;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment