Exemple #1
0
        private static void Build(ContainerBuilder builder)
        {
            builder
            .RegisterModule <AttributedMetadataModule>();

            // Using a Telemetry Client per request, so user context, etc is unique per request.
            builder
            .RegisterType <TelemetryClient>()
            .SingleInstance();

            builder
            .RegisterInstance(new MicrosoftAppCredentials(Config.MicrosoftApplicationId, Config.MicrosoftAppPassword))
            .AsSelf();

            var client = new DocumentClient(Config.DocumentDbUri, Config.DocumentDbKey);
            IBotDataStore <BotData> store = new DocumentDbBotDataStore(client);

            client.CreateCollectionIfDoesNotExist("botdb", "subscriptioncollection");

            builder
            .Register(c => client)
            .As <IDocumentClient>()
            .SingleInstance();

            builder
            .Register(c => store)
            .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore)
            .AsSelf()
            .SingleInstance();

            builder
            .Register(c =>
                      new CachingBotDataStore(
                          store,
                          CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
            .As <IBotDataStore <BotData> >()
            .AsSelf()
            .InstancePerLifetimeScope();

            // When debugging with the bot emulator we need to use the listening url from the emulator.
            // if (isDebugging && !string.IsNullOrEmpty(Config.EmulatorListeningUrl))
            // {
            //    builder.Register(c => new StateClient(new Uri(Config.EmulatorListeningUrl), microsoftAppCredentials));
            // }
            // else
            // {
            //    builder.Register(c => new StateClient(microsoftAppCredentials));
            // }
            builder
            .RegisterType <BotState>()
            .AsImplementedInterfaces();

            builder
            .RegisterType <BotDataFactory>()
            .As <IBotDataFactory>();

            builder
            .RegisterType <AuthenticationService>()
            .As <IAuthenticationService>();

            builder
            .RegisterType <VstsService>()
            .As <IVstsService>();

            builder
            .RegisterControllers(typeof(Bootstrap).Assembly)
            .Except <AuthorizeController>();

            builder
            .RegisterType <AuthorizeController>()
            .WithParameter("appSecret", Config.ApplicationSecret)
            .WithParameter("authorizeUrl", Config.AuthorizeUrl)
            .AsSelf();

            builder
            .RegisterType <ApprovalEventStrategy>()
            .As <IEventStrategy>();

            builder
            .RegisterType <MyApprovalSubscriptionStrategy>()
            .As <ISubscriptionStrategy>();

            builder
            .RegisterApiControllers(typeof(Bootstrap).Assembly);

            builder
            .RegisterAssemblyTypes(typeof(Bootstrap).Assembly)
            .Where(t => t.GetInterfaces().Any(i => i.IsAssignableFrom(typeof(IDialog <object>))))
            .Except <ConnectDialog>()
            .Except <RootDialog>()
            .AsImplementedInterfaces();

            builder
            .RegisterType <ConnectDialog>()
            .WithParameter("appId", Config.ApplicationId)
            .WithParameter("appScope", Config.ApplicationScope)
            .WithParameter("authorizeUrl", Config.AuthorizeUrl)
            .AsImplementedInterfaces();

            builder
            .RegisterType <RootDialog>()
            .AsSelf();
        }