Created
March 4, 2016 08:55
-
-
Save LexxFedoroff/4fe2a1c89d98b85f090f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Threading; | |
using Autofac; | |
namespace AutofacTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var builder = new ContainerBuilder(); | |
builder.RegisterModule<RootModule>(); | |
var container = builder.Build(); | |
Console.WriteLine("done"); | |
Console.ReadLine(); | |
} | |
} | |
public interface ISemaphor | |
{ | |
} | |
public sealed class Startable : IStartable | |
{ | |
private readonly ISemaphor[] _semaphors; | |
public Startable(ISemaphor[] semaphors) | |
{ | |
_semaphors = semaphors; | |
} | |
public void Start() | |
{ | |
} | |
} | |
public sealed class Singleton : ISemaphor | |
{ | |
private static int _count; | |
public Singleton() | |
{ | |
Interlocked.Increment(ref _count); | |
Debug.Assert(_count < 2); | |
} | |
} | |
public sealed class RootModule : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
builder.RegisterModule(new SubModule1()); | |
builder.RegisterModule(new SubModule2()); | |
} | |
} | |
public sealed class SubModule1 : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
builder.RegisterModule(new CoreModule()); | |
} | |
} | |
public sealed class SubModule2 : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
builder.RegisterModule(new CoreModule()); | |
} | |
} | |
public sealed class CoreModule : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
builder.RegisterType<Startable>().AsImplementedInterfaces(); | |
builder.RegisterType<Singleton>().AsImplementedInterfaces().SingleInstance(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment