protected override void Load(ContainerBuilder builder) { base.Load(builder); builder.RegisterModule(new FiberModule <DialogTask>()); // singleton components builder .Register(c => new ResourceManager("Microsoft.Bot.Builder.Resource.Resources", typeof(Resource.Resources).Assembly)) .As <ResourceManager>() .SingleInstance(); // every lifetime scope is driven by a message builder .Register((c, p) => p.TypedAs <IMessageActivity>()) .AsSelf() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // components not marked as [Serializable] builder .RegisterType <MicrosoftAppCredentials>() .AsSelf() .SingleInstance(); builder .RegisterType <BotIdResolver>() .As <IBotIdResolver>() .SingleInstance(); builder .Register(c => new ConnectorClientFactory(c.Resolve <IMessageActivity>(), c.Resolve <MicrosoftAppCredentials>())) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IConnectorClientFactory>().MakeConnectorClient()) .As <IConnectorClient>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IConnectorClientFactory>().MakeStateClient()) .As <IStateClient>() .InstancePerLifetimeScope(); builder .Register(c => new DetectChannelCapability(c.Resolve <IMessageActivity>())) .As <IDetectChannelCapability>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IDetectChannelCapability>().Detect()) .As <IChannelCapability>() .InstancePerLifetimeScope(); builder.RegisterType <ConnectorStore>() .AsSelf() .InstancePerLifetimeScope(); // If bot wants to use InMemoryDataStore instead of // ConnectorStore, the below registration should be used // as the inner IBotDataStore for CachingBotDataStore /*builder.RegisterType<InMemoryDataStore>() * .AsSelf() * .SingleInstance(); */ builder.Register(c => new CachingBotDataStore(c.Resolve <ConnectorStore>(), CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType <JObjectBotData>() .As <IBotData>() .InstancePerLifetimeScope(); builder .Register(c => new BotDataBagStream(c.Resolve <IBotData>().PrivateConversationData, BlobKey)) .As <Stream>() .InstancePerLifetimeScope(); builder .RegisterType <DialogTask>() .AsSelf() .As <IDialogStack>() .InstancePerLifetimeScope(); // Scorable implementing "/deleteprofile" builder .RegisterType <DeleteProfileScorable>() .As <IScorable <double> >() .InstancePerLifetimeScope(); builder .Register(c => { var cc = c.Resolve <IComponentContext>(); Func <IPostToBot> makeInner = () => { var task = cc.Resolve <DialogTask>(); IDialogStack stack = task; IPostToBot post = task; post = new ReactiveDialogTask(post, stack, cc.Resolve <IStore <IFiberLoop <DialogTask> > >(), cc.Resolve <Func <IDialog <object> > >()); post = new ExceptionTranslationDialogTask(post); post = new LocalizedDialogTask(post); post = new ScoringDialogTask <double>(post, stack, cc.Resolve <IComparer <double> >(), cc.Resolve <ITraits <double> >(), cc.Resolve <IScorable <double>[]>()); return(post); }; IPostToBot outer = new PersistentDialogTask(makeInner, cc.Resolve <IMessageActivity>(), cc.Resolve <IConnectorClient>(), cc.Resolve <IBotToUser>(), cc.Resolve <IBotData>()); outer = new PostUnhandledExceptionToUserTask(outer, cc.Resolve <IBotToUser>(), cc.Resolve <ResourceManager>(), cc.Resolve <TraceListener>()); return(outer); }) .As <IPostToBot>() .InstancePerLifetimeScope(); builder .RegisterType <AlwaysSendDirect_BotToUser>() .AsSelf() .As <IBotToUser>() .InstancePerLifetimeScope(); builder .RegisterType <DialogContext>() .As <IDialogContext>() .InstancePerLifetimeScope(); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); builder.RegisterModule(new FiberModule <DialogTask>()); // singleton components builder .Register(c => new ResourceManager("Microsoft.Bot.Builder.Resource.Resources", typeof(Resource.Resources).Assembly)) .As <ResourceManager>() .SingleInstance(); // every lifetime scope is driven by a message builder .Register((c, p) => p.TypedAs <IMessageActivity>()) .AsSelf() .AsImplementedInterfaces() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // make the address and cookie available for the lifetime scope builder .Register(c => Address.FromActivity(c.Resolve <IActivity>())) .AsImplementedInterfaces() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); builder .RegisterType <ResumptionCookie>() .AsSelf() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // components not marked as [Serializable] builder .RegisterType <MicrosoftAppCredentials>() .AsSelf() .SingleInstance(); builder // not resolving IEqualityComparer<IAddress> from container because it's a very local policy // and yet too broad of an interface. could explore using tags for registration overrides. .Register(c => new LocalMutualExclusion <IAddress>(new ConversationAddressComparer())) .As <IScope <IAddress> >() .SingleInstance(); builder .Register(c => new ConnectorClientFactory(c.Resolve <IAddress>(), c.Resolve <MicrosoftAppCredentials>())) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IConnectorClientFactory>().MakeConnectorClient()) .As <IConnectorClient>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IConnectorClientFactory>().MakeStateClient()) .As <IStateClient>() .InstancePerLifetimeScope(); builder .Register(c => new DetectChannelCapability(c.Resolve <IAddress>())) .As <IDetectChannelCapability>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IDetectChannelCapability>().Detect()) .As <IChannelCapability>() .InstancePerLifetimeScope(); builder.RegisterType <ConnectorStore>() .AsSelf() .InstancePerLifetimeScope(); // If bot wants to use InMemoryDataStore instead of // ConnectorStore, the below registration should be used // as the inner IBotDataStore for CachingBotDataStore /*builder.RegisterType<InMemoryDataStore>() * .AsSelf() * .SingleInstance(); */ builder.Register(c => new CachingBotDataStore(c.Resolve <ConnectorStore>(), CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType <JObjectBotData>() .AsSelf() .InstancePerLifetimeScope(); builder .Register(c => new DialogTaskManagerBotDataLoader(c.Resolve <JObjectBotData>(), c.Resolve <IDialogTaskManager>())) .As <IBotData>() .InstancePerLifetimeScope(); builder .Register((c, p) => new BotDataBagStream(p.TypedAs <IBotDataBag>(), p.TypedAs <string>())) .As <Stream>() .InstancePerDependency(); builder .Register(c => new DialogTaskManager(DialogModule.BlobKey, c.Resolve <JObjectBotData>(), c.Resolve <IStackStoreFactory <DialogTask> >(), c.Resolve <Func <IDialogStack, CancellationToken, IDialogContext> >())) .AsSelf() .As <IDialogTaskManager>() .InstancePerLifetimeScope(); builder .RegisterType <DialogContext>() .As <IDialogContext>() .InstancePerDependency(); builder .Register(c => { var cc = c.Resolve <IComponentContext>(); Func <string, IBotDataBag, IStore <IFiberLoop <DialogTask> > > make = (taskId, botDataBag) => { var stream = cc.Resolve <Stream>(TypedParameter.From(botDataBag), TypedParameter.From(taskId)); return(cc.Resolve <IStore <IFiberLoop <DialogTask> > >(TypedParameter.From(stream))); }; return(make); }) .As <Func <string, IBotDataBag, IStore <IFiberLoop <DialogTask> > > >() .InstancePerDependency(); builder.Register(c => c.Resolve <IDialogTaskManager>().DialogTasks[0]) .As <IDialogStack>() .As <IDialogTask>() .InstancePerLifetimeScope(); // Scorable implementing "/deleteprofile" builder .Register(c => new Regex("^(\\s)*/deleteprofile", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace)) .Keyed <Regex>(Key_DeleteProfile_Regex) .SingleInstance(); builder .Register(c => new DeleteProfileScorable(c.Resolve <IDialogStack>(), c.Resolve <IBotData>(), c.Resolve <IBotToUser>(), c.ResolveKeyed <Regex>(Key_DeleteProfile_Regex))) .As <IScorable <IActivity, double> >() .InstancePerLifetimeScope(); builder .Register(c => { var cc = c.Resolve <IComponentContext>(); Func <IActivity, IResolver> make = activity => { var resolver = NoneResolver.Instance; resolver = new EnumResolver(resolver); resolver = new AutofacResolver(cc, resolver); resolver = new ArrayResolver(resolver, activity, cc.Resolve <IDialogStack>(), cc.Resolve <IBotToUser>(), cc.Resolve <IBotData>(), cc.Resolve <IDialogTaskManager>()); resolver = new ActivityResolver(resolver); return(resolver); }; return(make); }) .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType <DialogRouter>() .Keyed <IScorable <IActivity, double> >(Key_Dialog_Router) .InstancePerLifetimeScope(); builder .Register(c => { var cc = c.Resolve <IComponentContext>(); Func <IPostToBot> makeInner = () => { IPostToBot post = new ReactiveDialogTask(cc.Resolve <IDialogTask>(), cc.Resolve <Func <IDialog <object> > >()); post = new ScoringDialogTask <double>(post, cc.ResolveKeyed <IScorable <IActivity, double> >(Key_Dialog_Router)); return(post); }; IPostToBot outer = new PersistentDialogTask(makeInner, cc.Resolve <IBotData>()); outer = new SerializingDialogTask(outer, cc.Resolve <IAddress>(), c.Resolve <IScope <IAddress> >()); outer = new ExceptionTranslationDialogTask(outer); outer = new LocalizedDialogTask(outer); outer = new PostUnhandledExceptionToUserTask(outer, cc.Resolve <IBotToUser>(), cc.Resolve <ResourceManager>(), cc.Resolve <TraceListener>()); outer = new LogPostToBot(outer, cc.Resolve <IActivityLogger>()); return(outer); }) .As <IPostToBot>() .InstancePerLifetimeScope(); builder .RegisterType <NullActivityLogger>() .AsImplementedInterfaces() .SingleInstance(); builder .RegisterType <AlwaysSendDirect_BotToUser>() .AsSelf() .InstancePerLifetimeScope(); builder .Register(c => new LogBotToUser( new MapToChannelData_BotToUser(c.Resolve <AlwaysSendDirect_BotToUser>(), new [] { new KeyboardCardMapper() }), c.Resolve <IActivityLogger>())) .As <IBotToUser>() .InstancePerLifetimeScope(); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); builder.RegisterModule(new FiberModule <DialogTask>()); // singleton components builder .Register(c => new ResourceManager("Microsoft.Bot.Builder.Resource.Resources", typeof(Resource.Resources).Assembly)) .As <ResourceManager>() .SingleInstance(); // every lifetime scope is driven by a message builder .Register((c, p) => p.TypedAs <IMessageActivity>()) .AsSelf() .AsImplementedInterfaces() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // make the address and cookie available for the lifetime scope builder .RegisterType <Address>() .AsSelf() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); builder .RegisterType <ResumptionCookie>() .AsSelf() .InstancePerMatchingLifetimeScope(LifetimeScopeTag); // components not marked as [Serializable] builder .RegisterType <MicrosoftAppCredentials>() .AsSelf() .SingleInstance(); builder .RegisterType <BotIdResolver>() .As <IBotIdResolver>() .SingleInstance(); builder // not resolving IEqualityComparer<Address> from container because it's a very local policy // and yet too broad of an interface. could explore using tags for registration overrides. .Register(c => new LocalMutualExclusion <Address>(new ConversationAddressComparer())) .As <IScope <Address> >() .SingleInstance(); builder .Register(c => new ConnectorClientFactory(c.Resolve <IMessageActivity>(), c.Resolve <MicrosoftAppCredentials>())) .As <IConnectorClientFactory>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IConnectorClientFactory>().MakeConnectorClient()) .As <IConnectorClient>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IConnectorClientFactory>().MakeStateClient()) .As <IStateClient>() .InstancePerLifetimeScope(); builder .Register(c => new DetectChannelCapability(c.Resolve <IMessageActivity>())) .As <IDetectChannelCapability>() .InstancePerLifetimeScope(); builder .Register(c => c.Resolve <IDetectChannelCapability>().Detect()) .As <IChannelCapability>() .InstancePerLifetimeScope(); builder.RegisterType <ConnectorStore>() .AsSelf() .InstancePerLifetimeScope(); // If bot wants to use InMemoryDataStore instead of // ConnectorStore, the below registration should be used // as the inner IBotDataStore for CachingBotDataStore /*builder.RegisterType<InMemoryDataStore>() * .AsSelf() * .SingleInstance(); */ builder.Register(c => new CachingBotDataStore(c.Resolve <ConnectorStore>(), CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); builder .RegisterType <JObjectBotData>() .As <IBotData>() .InstancePerLifetimeScope(); builder .Register(c => new BotDataBagStream(c.Resolve <IBotData>().PrivateConversationData, BlobKey)) .As <Stream>() .InstancePerLifetimeScope(); builder .RegisterType <DialogTask>() .AsSelf() .As <IDialogStack>() .InstancePerLifetimeScope(); // Scorable implementing "/deleteprofile" builder .RegisterType <DeleteProfileScorable>() .As <IScorable <double> >() .InstancePerLifetimeScope(); builder .Register(c => { var stack = c.Resolve <IDialogStack>(); var fromStack = stack.Frames.Select(f => f.Target).OfType <IScorable <double> >(); var fromGlobal = c.Resolve <IScorable <double>[]>(); // since the stack of scorables changes over time, this should be lazy var lazyScorables = fromStack.Concat(fromGlobal); var scorable = new CompositeScorable <double>(c.Resolve <IComparer <double> >(), c.Resolve <ITraits <double> >(), lazyScorables); return(scorable); }) .InstancePerLifetimeScope() .AsSelf(); builder .Register(c => { var cc = c.Resolve <IComponentContext>(); Func <IPostToBot> makeInner = () => { var task = cc.Resolve <DialogTask>(); IDialogStack stack = task; IPostToBot post = task; post = new ReactiveDialogTask(post, stack, cc.Resolve <IStore <IFiberLoop <DialogTask> > >(), cc.Resolve <Func <IDialog <object> > >()); post = new ExceptionTranslationDialogTask(post); post = new LocalizedDialogTask(post); post = new ScoringDialogTask <double>(post, stack, cc.Resolve <CompositeScorable <double> >()); return(post); }; IPostToBot outer = new PersistentDialogTask(makeInner, cc.Resolve <IMessageActivity>(), cc.Resolve <IConnectorClient>(), cc.Resolve <IBotToUser>(), cc.Resolve <IBotData>()); outer = new SerializingDialogTask(outer, cc.Resolve <Address>(), c.Resolve <IScope <Address> >()); outer = new PostUnhandledExceptionToUserTask(outer, cc.Resolve <IBotToUser>(), cc.Resolve <ResourceManager>(), cc.Resolve <TraceListener>()); return(outer); }) .As <IPostToBot>() .InstancePerLifetimeScope(); builder .RegisterType <AlwaysSendDirect_BotToUser>() .AsSelf() .As <IBotToUser>() .InstancePerLifetimeScope(); builder .RegisterType <DialogContext>() .As <IDialogContext>() .InstancePerLifetimeScope(); }