Skip to content

Instantly share code, notes, and snippets.

View blazey's full-sized avatar

Blazey Software blazey

View GitHub Profile
@blazey
blazey / InstallScheduler.cs
Created June 18, 2015 11:09
Conventional configuration and explicit configuration.
public class InstallScheduler : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
new InstallFeature<IScheduleCollectionFromAgent>().Install(container, store);
container.Register(
Component.For<IBackgroundJobClient>().ImplementedBy<BackgroundJobClient>());
JobActivator.Current = new WindsorJobActivator(container.Kernel);
@blazey
blazey / InstallFeature.cs
Last active September 16, 2015 10:29
Install features by namespace
internal class InstallFeature<TInSameNamespaceAs> : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Classes.FromThisAssembly()
.InSameNamespaceAs<TInSameNamespaceAs>()
.Unless(type => type.IsAssignableToGenericType(typeof (IEventHandler<>)))
.Unless(type => type.IsAssignableToGenericType(typeof (IResourceCommandHandler<>))
.Unless(type => typeof (Now).IsAssignableFrom(type))
.Unless(type => typeof (IWindsorInstaller).IsAssignableFrom(type))
@blazey
blazey / InstallApi.cs
Created June 18, 2015 10:53
Installer example
public class InstallApi : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
new InstallFeature<IController>().Install(container, store);
}
}
@blazey
blazey / Bootstrap.cs
Created June 18, 2015 10:43
Bootstrap example
public class Bootstrap : IDisposable
{
private readonly Lazy<IWindsorContainer> _container = new Lazy<IWindsorContainer>(() =>
{
var container = new WindsorContainer();
container.Install(FromAssembly.This());
container.Register(Component.For<IWindsorContainer>().Instance(container));
return container;
});
@blazey
blazey / RegisterComponent.cs
Created June 18, 2015 10:33
Windsor facility to swap registered components with configured test friendly substitutions.
internal class RegisterComponent<TService> where TService : class
{
private readonly Func<TService> _factory;
private readonly Type _componentType;
public static void Register(IWindsorContainer container, Func<TService> factory, Type componentType)
{
if (null == componentType)
{
new RegisterComponent<TService>(factory).Register(container);
@blazey
blazey / Spec.cs
Last active August 29, 2015 14:23
Enabling in-memory integration tests by swapping out components in tests, post normal registration of components in container
_bootstrap = new Bootstrap();
_bootstrap.AddFacility<TestSubstituteFacility>(config =>
{
config.WithContainer(_bootstrap.Container)
.Substitute<IDataLakeWriter>(sub => sub.Instance(_dataLakeWriterMockery.Mock))
.Substitute<ICollectorAgentDispatcher>(sub => sub.Stub())
.Substitute<IBackgroundJobClient>(sub => sub.Stub())
.Substitute<ISchedulesReportWriter>(sub => sub.Stub())
.Substitute<IRepository<Resource>>(sub => sub.Instance(() =>