public static IContainer Build(Options options, params object[] singletons) { var builder = new ContainerBuilder(); if (options.HasFlag(Options.ResolveDialogFromContainer)) { builder.RegisterModule(new DialogModule()); } else { builder.RegisterModule(new DialogModule_MakeRoot()); } // make a "singleton" MockConnectorFactory per unit test execution IConnectorClientFactory factory = null; builder .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve <IAddress>().BotId))) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); if (options.HasFlag(Options.Reflection)) { builder.RegisterModule(new ReflectionSurrogateModule()); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }
public static IContainer Build(Options options, params object[] singletons) { var builder = new ContainerBuilder(); builder.RegisterModule(new DialogModule_MakeRoot()); // make a "singleton" MockConnectorFactory per unit test execution IConnectorClientFactory factory = null; builder .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve <IAddress>().BotId))) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); var r = builder .Register <Queue <Activity> >(c => ((TestAdapter)c.Resolve <Microsoft.Bot.Builder.ITurnContext>().Adapter).ActiveQueue) .AsSelf() .InstancePerLifetimeScope(); if (options.HasFlag(Options.InMemoryBotDataStore)) { //Note: memory store will be single instance for the bot builder.RegisterType <InMemoryDataStore>() .AsSelf() .SingleInstance(); builder.Register(c => new CachingBotDataStore(c.Resolve <InMemoryDataStore>(), CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); } if (options.HasFlag(Options.NeedsInputHint)) { builder.Register(c => new AlwaysNeedInputHintChannelCapability(new ChannelCapability(c.Resolve <IAddress>()))) .AsImplementedInterfaces() .InstancePerLifetimeScope(); } foreach (var singleton in singletons) { builder .Register(c => singleton) .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType()); } return(builder.Build()); }