Skip to content

Instantly share code, notes, and snippets.

View mookid8000's full-sized avatar
💭
Pressing buttons.

Mogens Heller Grabe mookid8000

💭
Pressing buttons.
View GitHub Profile
}
}
}
}
break;
}
}
}
}
Dictionary<string, bool> usedGuids = new Dictionary<string, bool>();
private string CreateUniqueGuid()
{
string newGuid = Guid.NewGuid().ToString();
if (usedGuids.ContainsKey(newGuid))
{
throw new Exception();
}
@mookid8000
mookid8000 / gist:905204
Created April 6, 2011 05:48
Subscribe to types discovered via reflection
foreach(var derivedMessageType in GetAllMessageTypes().Where(t => typeof(IBaseMessage).IsAssignableFrom(t))
{
bus.GetType().GetMethod("Subscribe").MakeGenericMethod(derivedMessageType).Invoke(bus, new object[0]);
}
@mookid8000
mookid8000 / gist:905531
Created April 6, 2011 12:00
NServiceBus app.config example
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig InputQueue="someClient"
ErrorQueue="error"
NumberOfWorkerThreads="1"
@mookid8000
mookid8000 / gist:905536
Created April 6, 2011 12:03
NServiceBus bus config sample
var bus = Configure.With()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport().IsTransactional(false)
.UnicastBus().LoadMessageHandlers()
.CreateBus()
.Start();
@mookid8000
mookid8000 / gist:905624
Created April 6, 2011 13:21
NServiceBus endpoint config example publisher
public class EndpointConfiguration : IConfigureThisEndpoint,
IWantCustomLogging,
IWantCustomInitialization
{
public void Init()
{
Configure.With()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
@mookid8000
mookid8000 / gist:951560
Created May 2, 2011 12:52
NServiceBus still doesn't seem to release tracked components
public class EndpointConfiguration : IConfigureThisEndpoint,
AsA_Server,
IWantCustomInitialization,
IWantToRunAtStartup
{
readonly IWindsorContainer container;
public EndpointConfiguration()
{
container = new WindsorContainerDecorator()
@mookid8000
mookid8000 / gist:1137706
Created August 10, 2011 18:28
being explicit about message types
public interface ICommand : IMessage {}
public interface IEvent : IMessage {}
public interface IRequest : IMessage {}
public interface IReply : IMessage {}
@mookid8000
mookid8000 / gist:1251717
Created September 29, 2011 19:39
.NET regexes to extract tags and mentions
static readonly Regex TagsRegex = new Regex(@"(?:(?<=\s)|^)#(\w*[A-Za-z_]+\w*)");
static readonly Regex MentionsRegex = new Regex(@"(?:(?<=\s)|^)\@(\w*[A-Za-z_]+\w*)");
@mookid8000
mookid8000 / gist:1510130
Created December 22, 2011 12:24
Rebus example configuration
var adapter = new MyContainerAdapter(favoriteContainer);
Configure.With(adapter)
.Transport(t => t.UseMsmq("some_input_queue"))
.Serialization(s => s.UseJsonSerializer())
.Sagas(s => s.StoreInSqlServer(connectionstring, "saga_table", "saga_index_table"))
.Subscriptions(s => s.StoreInSqlServer(connectionstring, "subscriptions"))
.SpecifyOrderOfHandlers(h => h.First<SomeType>().Then<AnotherType>())
.Logging(l => l.Log4Net())
.DetermineEndpoints(d => d.FromRebusMappingsSection())