CallingModule.cs
1 using Autofac;
2 using System;
3 using System.Net.Http;
4 
5 namespace Microsoft.Bot.Builder.Calling
6 {
10  public sealed class CallingModule : Module
11  {
12  public static readonly object LifetimeScopeTag = typeof(CallingModule);
13 
14  public static ILifetimeScope BeginLifetimeScope(ILifetimeScope scope, HttpRequestMessage request)
15  {
16  var inner = scope.BeginLifetimeScope(LifetimeScopeTag);
17  inner.Resolve<HttpRequestMessage>(TypedParameter.From(request));
18  return inner;
19  }
20 
21  protected override void Load(ContainerBuilder builder)
22  {
23  base.Load(builder);
24 
25  builder
26  .Register((c, p) => p.TypedAs<HttpRequestMessage>())
27  .AsSelf()
28  .InstancePerMatchingLifetimeScope(LifetimeScopeTag);
29 
30  builder
31  .RegisterType<CallingContext>()
32  .AsSelf()
33  .InstancePerMatchingLifetimeScope(LifetimeScopeTag);
34 
35  builder
37  .AsSelf()
38  .SingleInstance();
39 
40  builder
41  .Register(c => new CallingBotService(c.Resolve<CallingBotServiceSettings>()))
42  .AsSelf()
43  .As<ICallingBotService>()
44  .SingleInstance();
45 
46  }
47  }
48 
49  public sealed class CallingModule_MakeBot : Module
50  {
51  protected override void Load(ContainerBuilder builder)
52  {
53  base.Load(builder);
54 
55  builder.RegisterModule(new CallingModule());
56 
57  // First call to handler will register single instance of the calling bot
58  // it can be changed to create a new instance per matching lifetime
59  builder
60  .Register((c, p) => p.TypedAs<Func<ICallingBotService, ICallingBot>>())
61  .AsSelf()
62  .SingleInstance();
63  //.InstancePerMatchingLifetimeScope(CallingModule.LifetimeScopeTag);
64 
65  builder
66  .Register(c =>
67  {
68  var makeBot = c.Resolve<Func<ICallingBotService, ICallingBot>>();
69  var callingBotService = c.Resolve<ICallingBotService>();
70  return makeBot(callingBotService);
71  }
72  )
73  .As<ICallingBot>()
74  .SingleInstance();
75  //.InstancePerMatchingLifetimeScope(CallingModule.LifetimeScopeTag);
76  }
77 
78  public static void Register(ILifetimeScope scope, Func<ICallingBotService, ICallingBot> MakeCallingBot)
79  {
80  scope.Resolve<Func<ICallingBotService, ICallingBot>>(TypedParameter.From(MakeCallingBot));
81  }
82  }
83 }
The context for this request. It is reponsible in parsing the calling request before calling into ICa...
override void Load(ContainerBuilder builder)
static ILifetimeScope BeginLifetimeScope(ILifetimeScope scope, HttpRequestMessage request)
static void Register(ILifetimeScope scope, Func< ICallingBotService, ICallingBot > MakeCallingBot)
static CallingBotServiceSettings LoadFromCloudConfiguration()
Loads core bot library configuration from the cloud service configuration
Autofac module for Calling components.
override void Load(ContainerBuilder builder)