Skip to content

Instantly share code, notes, and snippets.

@cammerman
Created November 30, 2010 03:06
Show Gist options
  • Save cammerman/721076 to your computer and use it in GitHub Desktop.
Save cammerman/721076 to your computer and use it in GitHub Desktop.
Autofac Blog Post Samples
interface IComparisonWindow { /* ... */ }
class ComparisonWindow : IComparisonWindow { /* ... */ }
enum EComparisonSide
{
Left,
Right
}
builder
.RegisterType<ComparisonWindow>()
.As<IComparisonWindow>()
.InstancePerMatchingLifetimeScope(EComparisonSide.Left)
builder
.RegisterType<ComparisonWindow>()
.As<IComparisonWindow>()
.InstancePerMatchingLifetimeScope(EComparisonSide.Right);
interface IAlertDialog { /* ... */ }
class AlertDialog : IAlertDialog { /* ... */ }
builder
.RegisterType<AlertDialog>()
.As<IAlertDialog>()
.InstancePerDependency();
interface IDifferenceMap { /* ... */ }
class DifferenceMap : IDifferenceMap { /* ... */ }
builder
.RegisterType<DifferenceMap>()
.As<IDifferenceMap>()
.InstancePerLifetimeScope();
class IoCBootstrap
{
public virtual IContainer MainContainer
{
get;
protected set;
}
public virtual IContainer LeftContainer
{
get;
protected set;
}
public virtual IContainer RightContainer
{
get;
protected set;
}
protected virtual ContainerBuilder Builder
{
get;
private set;
}
public void RegisterComponents()
{
Builder = new ContainerBuilder();
/* Registration code */
}
public void BuildResolvers()
{
MainContainer = Builder.Build();
LeftContainer = MainContainer.BeginLifetimeScope(EComparisonSide.Left);
RightContainer = MainContainer.BeginLifetimeScope(EComparisonSide.Right);
}
}
interface IFileAccess { /* ... */ }
class FileAccess : IFileAccess { /* ... */ }
var builder = ContainerBuilder();
builder
.RegisterType<Repository>()
.As<IRepository>()
.SingleInstance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment