-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContinuousRunnerModule.cs
88 lines (71 loc) · 3.42 KB
/
ContinuousRunnerModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Linq;
using Autofac;
using Autofac.Builder;
using Autofac.Core;
using Autofac.Features.Scanning;
using Microsoft.ClearScript;
namespace ContinuousRunner
{
using Frameworks.RequireJs;
using Impl;
using Work;
public class ContinuousRunnerModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
var except = new[] {typeof (ExecuteScriptWork)};
var singleInstanceRegisters = new[]
{
typeof (CachedScripts),
typeof (ScriptCollection),
typeof (RequirePackageSystem)
};
foreach (var r in singleInstanceRegisters)
{
builder.RegisterType(r)
.AsImplementedInterfaces()
.SingleInstance()
.OnActivating(ActivateInject);
}
builder.Register((c, p) => new TestCollection(p.TypedAs<IScript>()))
.AsImplementedInterfaces()
.OnActivating(ActivateInject);
var completeRegister = builder.RegisterAssemblyTypes(typeof(ContinuousRunnerModule).Assembly)
.AsImplementedInterfaces()
.OnActivating(ActivateInject);
builder.Register((c, p) => new ExecuteScriptWork(c.Resolve<IRunner<IScript>>(), p.TypedAs<IScript>(), p.TypedAs<string>()))
.As<ExecuteScriptWork>();
var declareExcept = typeof(Autofac.RegistrationExtensions).GetMethod("Except",
new[] {typeof(IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle>)});
completeRegister =
singleInstanceRegisters.Concat(except)
.Select(r => declareExcept.MakeGenericMethod(r))
.Aggregate(completeRegister,
(current, method) =>
method.Invoke(current, new object[] {current}) as
IRegistrationBuilder
<object, ScanningActivatorData, DynamicRegistrationStyle>);
builder.Register(
c =>
{
var scriptLoader = c.Resolve<ICachedScripts>();
return c.Resolve<IRequireConfigurationLoader>().Load(c.Resolve<IScriptCollection>().GetScriptFiles(), f => scriptLoader.Load(f));
})
.As<IRequireConfiguration>()
.SingleInstance()
.OnActivating(ActivateInject);
builder.Register((c, p) =>
{
var parameters = p.ToArray();
return new RequireDefine(parameters.TypedAs<ScriptEngine>(),
parameters.TypedAs<IScript>());
})
.OnActivating(ActivateInject);
}
private static void ActivateInject<T>(IActivatingEventArgs<T> args)
{
PropertyInjector.InjectProperties(args.Context, args.Instance);
}
}
}