Пример #1
0
        public static void Register(HttpConfiguration config)
        {
            var builder = new ContainerBuilder();

            builder
                .Register(c => new BingTranslatorClient("Test187871", "dAnT3r/eIc8KedBRUgRCV+juxpf4Wl312jn1Bd2SXzk="))
                .As<ITranslator>()
                .InstancePerDependency();

            builder
                .Register(c => new LogBotToUser(new MapToChannelData_BotToUser(
                        c.Resolve<AlwaysSendDirect_BotToUser>(),
                        new List<IMessageActivityMapper> { new KeyboardCardMapper() }), c.Resolve<IActivityLogger>()))
                    .AsSelf()
                    .InstancePerLifetimeScope();

            builder
                .Register(c => new TranslatedBotToUser(c.Resolve<LogBotToUser>(),
                        c.Resolve<ITranslator>()))
                    .As<IBotToUser>()
                    .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<TraitsScorable<IActivity, double>>());
                        return post;
                    };

                    IPostToBot outer = new PersistentDialogTask(makeInner, cc.Resolve<IBotData>());
                    outer = new SerializingDialogTask(outer, cc.Resolve<IAddress>(), c.Resolve<IScope<IAddress>>());
                    outer = new PostUnhandledExceptionToUserTask(outer, cc.Resolve<IBotToUser>(), cc.Resolve<ResourceManager>(), cc.Resolve<TraceListener>());
                    outer = new LogPostToBot(outer, cc.Resolve<IActivityLogger>());
                    outer = new TranslatedPostToBot(outer, cc.Resolve<ITranslator>());
                    return outer;
                })
                .As<IPostToBot>()
                .InstancePerLifetimeScope();

            builder.Update(Conversation.Container);
        }
Пример #2
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterModule(new FiberModule<DialogTask>());

            // 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>()
                .As<IBotDataStore<BotData>>()
                .AsSelf()
                .InstancePerLifetimeScope();

            // If bot wants to use InMemoryDataStore instead of
            // ConnectorStore, the below registration should be used
            /*builder.RegisterType<InMemoryDataStore>()
                .As<IBotDataStore<BotData>>()
                .AsSelf()
                .SingleInstance(); */

            builder.RegisterType<CachingBotDataStore_LastWriteWins>()
                .As<IBotDataStore>()
                .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 LocalizedDialogTask(post);
                        post = new ScoringDialogTask<double>(post, stack, cc.Resolve<IComparer<double>>(), cc.Resolve<ITraits<double>>(), cc.Resolve<IScorable<double>[]>());
                        return post;
                    };

                    var outer = new PersistentDialogTask(makeInner, cc.Resolve<IMessageActivity>(), cc.Resolve<IConnectorClient>(), cc.Resolve<IBotToUser>(), cc.Resolve<IBotData>());
                    return outer;
                })
                .As<IPostToBot>()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<AlwaysSendDirect_BotToUser>()
                .AsSelf()
                .As<IBotToUser>()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<DialogContext>()
                .As<IDialogContext>()
                .InstancePerLifetimeScope();
        }
Пример #3
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterModule(new FiberModule<DialogTask>());

            // every lifetime scope is driven by a message

            builder
                .Register((c, p) => p.TypedAs<Message>())
                .AsSelf()
                .InstancePerMatchingLifetimeScope(LifetimeScopeTag);

            // components not marked as [Serializable]

            builder
                .RegisterType<ConnectorClientCredentials>()
                .AsSelf()
                .SingleInstance();

            builder
                .Register(c => new DetectEmulatorFactory(c.Resolve<Message>(), new Uri("http://localhost:9000"), c.Resolve<ConnectorClientCredentials>()))
                .As<IConnectorClientFactory>()
                .InstancePerLifetimeScope();

            builder
                .Register(c => c.Resolve<IConnectorClientFactory>().Make())
                .As<IConnectorClient>()
                .InstancePerLifetimeScope();

            builder
               .Register(c => new DetectChannelCapability(c.Resolve<Message>()))
               .As<IDetectChannelCapability>()
               .InstancePerLifetimeScope();

            builder
                .Register(c => c.Resolve<IDetectChannelCapability>().Detect())
                .As<IChannelCapability>()
                .InstancePerLifetimeScope();

            builder.RegisterType<MessageBackedStore>()
                .As<IBotDataStore>()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<JObjectBotData>()
                .As<IBotData>()
                .InstancePerLifetimeScope();

            builder
                .Register(c => new BotDataBagStream(c.Resolve<IBotData>().PerUserInConversationData, BlobKey))
                .As<Stream>()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<DialogTask>()
                .AsSelf()
                .As<IDialogStack>()
                .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 LocalizedDialogTask(post);
                        post = new ScoringDialogTask<double>(post, stack, cc.Resolve<IComparer<double>>(), cc.Resolve<ITraits<double>>(), cc.Resolve<IScorable<double>[]>());
                        return post;
                    };

                    var outer = new PersistentDialogTask(makeInner, cc.Resolve<Message>(), cc.Resolve<IConnectorClient>(), cc.Resolve<IBotToUser>(), cc.Resolve<IBotData>());
                    return outer;
                })
                .As<IPostToBot>()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<SendLastInline_BotToUser>()
                .AsSelf()
                .As<IBotToUser>()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<DialogContext>()
                .As<IDialogContext>()
                .InstancePerLifetimeScope();
        }