Skip to content

Instantly share code, notes, and snippets.

Blazey Software blazey

View GitHub Profile
@blazey
blazey / InstallScheduler.cs
Created Jun 18, 2015
Conventional configuration and explicit configuration.
View InstallScheduler.cs
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 Sep 16, 2015
Install features by namespace
View InstallFeature.cs
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 Jun 18, 2015
Installer example
View InstallApi.cs
public class InstallApi : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
new InstallFeature<IController>().Install(container, store);
}
}
@blazey
blazey / Bootstrap.cs
Created Jun 18, 2015
Bootstrap example
View Bootstrap.cs
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 Jun 18, 2015
Windsor facility to swap registered components with configured test friendly substitutions.
View RegisterComponent.cs
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 Aug 29, 2015
Enabling in-memory integration tests by swapping out components in tests, post normal registration of components in container
View Spec.cs
_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(() =>
You can’t perform that action at this time.