public static void Configure() { ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType <RootDialog>().InstancePerDependency(); builder.RegisterType <QnAMakerService>().Keyed <IQnAMakerService>(FiberModule.Key_DoNotSerialize).AsImplementedInterfaces(); #region BotState var uri = new Uri(ConfigurationManager.AppSettings["CosmosDB.Uri"]); var key = ConfigurationManager.AppSettings["CosmosDB.Key"]; var database = ConfigurationManager.AppSettings["CosmosDB.Database"]; var botStateCollection = ConfigurationManager.AppSettings["CosmosDB.BotStateCollection"]; var store = new DocumentDbBotDataStore(uri, key, database, botStateCollection); 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(); #endregion builder.Update(container: Conversation.Container); }
protected void Application_Start() { var stateManager = ConfigurationManager.AppSettings["BotStateManager"]; IBotDataStore <BotData> store = null; if ("DocumentDb".Equals(stateManager)) { var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var key = ConfigurationManager.AppSettings["DocumentDbKey"]; store = new DocumentDbBotDataStore(uri, key); } Conversation.UpdateContainer( builder => { if (store != null) { 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(); } }); GlobalConfiguration.Configure(WebApiConfig.Register); }
private void RegisterBotDependencies() { Conversation.UpdateContainer(builder => { builder.RegisterModule(new ReflectionSurrogateModule()); builder.RegisterModule <SFBotModule>(); builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); //builder.RegisterControllers(typeof(WebApiApplication).Assembly); Uri docDbEmulatorUri = new Uri(ConfigurationManager.AppSettings["EndPointUrl"]); string docDbEmulatorKey = ConfigurationManager.AppSettings["AuthorizationKey"]; string docbdId = ConfigurationManager.AppSettings["DatabaseId"]; // Bot Storage: Here we register the state storage for your bot. // Default store: volatile in-memory store - Only for prototyping! // We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own! // For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure //var store = new InMemoryDataStore(); // Other storage options // var store = new TableBotDataStore("...DataStorageConnectionString..."); // requires Microsoft.BotBuilder.Azure Nuget package // var store = new DocumentDbBotDataStore("cosmos db uri", "cosmos db key"); // requires Microsoft.BotBuilder.Azure Nuget package var store = new DocumentDbBotDataStore(docDbEmulatorUri, docDbEmulatorKey, docbdId); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); }); //DependencyResolver.SetResolver(new AutofacDependencyResolver(Conversation.Container)); }
protected void Application_Start() { // Bot Storage: This is a great spot to register the private state storage for your bot. // We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own! // For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure var docDbServiceEndpoint = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var docDbEmulatorKey = ConfigurationManager.AppSettings["DocumentDbKey"]; Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var store = new DocumentDbBotDataStore(docDbServiceEndpoint, docDbEmulatorKey); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); // Using Azure Table Storage //var store = new TableBotDataStore(ConfigurationManager.AppSettings["AzureWebJobsStorage"]); // requires Microsoft.BotBuilder.Azure Nuget package //// To use CosmosDb or InMemory storage instead of the default table storage, uncomment the corresponding line below //// var store = new DocumentDbBotDataStore("cosmos db uri", "cosmos db key"); // requires Microsoft.BotBuilder.Azure Nuget package //// var store = new InMemoryDataStore(); // volatile in-memory store //builder.Register(c => store) // .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore) // .AsSelf() // .SingleInstance(); }); GlobalConfiguration.Configure(WebApiConfig.Register); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); // This will create a CosmosDB store, suitable for production // NOTE: Requires an actual CosmosDB instance and configuration in // PrivateSettings.config var databaseUri = new Uri(ConfigurationManager.AppSettings["DatabaseUri"]); var databaseKey = ConfigurationManager.AppSettings["DatabaseKey"]; var store = new DocumentDbBotDataStore(databaseUri, databaseKey); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); }); // Initialize approvals database DatabaseHelper.Initialize(); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); // Bot Storage: Here we register the state storage for your bot. // Default store: volatile in-memory store - Only for prototyping! // We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own! // For samples and documentation, see: [https://github.com/Microsoft/BotBuilder-Azure](https://github.com/Microsoft/BotBuilder-Azure) //var store = new InMemoryDataStore(); //// Other storage options //// var store = new TableBotDataStore("...DataStorageConnectionString..."); // requires Microsoft.BotBuilder.Azure Nuget package var store = new DocumentDbBotDataStore(new Uri(ConfigurationManager.AppSettings["CosmosEndpoint"]), ConfigurationManager.AppSettings["CosmosKey"], ConfigurationManager.AppSettings["CosmosDatataseName"], ConfigurationManager.AppSettings["CosmosCollectionName"]); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); }); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var key = ConfigurationManager.AppSettings["DocumentDbKey"]; var store = new DocumentDbBotDataStore(uri, key); var config = GlobalConfiguration.Configuration; Conversation.UpdateContainer( builder => { 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(); // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterWebApiFilterProvider(config); builder.RegisterModule <BotModule>(); }); config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container); }
private static async Task <IBotDataStore <BotData> > CreateDocumentDbStore(string botdb = "botdb") { var docClient = new DocumentClient(new Uri("https://localhost:8081"), "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="); var database = docClient.CreateDatabaseQuery().Where(db => db.Id == botdb).ToArray().FirstOrDefault(); if (database != null) { await docClient.DeleteDatabaseAsync(database.SelfLink); } var targetStore = new DocumentDbBotDataStore(docClient); return(targetStore); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Create Conversation State using MemoryStorage (conversations will be reset on server restart) IStorage conversationStorage = new MemoryStorage(); var conversationState = new ConversationState(conversationStorage); services.AddSingleton <ConversationState>(conversationState); //Uri docDbEmulatorUri = new Uri("https://localhost:8081"); //const string docDbEmulatorKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; // DocumentDbBotDataStore for V3V4 User State Uri docDbEmulatorUri = new Uri(Configuration["v3CosmosEndpoint"]); var documentDbBotDataStore = new DocumentDbBotDataStore(docDbEmulatorUri, Configuration["v3CosmosKey"], databaseId: Configuration["v3CosmosDatataseName"], collectionId: Configuration["v3CosmosCollectionName"]); // SqlBotDataStore for V3V4 User State //var sqlConnectionString = Configuration.GetConnectionString("SqlBotData"); //var sqlBotDataStore = new SqlBotDataStore(sqlConnectionString); // TableBotDataStore for V3V4 User State //var tableConnectionString = Configuration.GetConnectionString("AzureTable"); //var tableBotDataStore = new TableBotDataStore(tableConnectionString); // TableBotDataStore2 for V3V4 User State //var tableBotDataStore2 = new TableBotDataStore2(tableConnectionString); // Create the V3V4Storage layer bridge, providing a V3 storage. // Then use that storage to create a V3V4State, and inject as a singleton var v3v4Storage = new V3V4Storage(documentDbBotDataStore); //var v3v4Storage = new V3V4Storage(sqlBotDataStore); //var v3v4Storage = new V3V4Storage(tableBotDataStore); //var v3v4Storage = new V3V4Storage(tableBotDataStore2); services.AddSingleton <V3V4State>(new V3V4State(v3v4Storage)); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); services.AddSingleton <MainDialog>(); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient <IBot, EchoBot <MainDialog> >(); }
public static void Register(HttpConfiguration config) { // Json settings config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented; JsonConvert.DefaultSettings = () => new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), Formatting = Newtonsoft.Json.Formatting.Indented, NullValueHandling = NullValueHandling.Ignore, }; // Web API configuration and services //Fixed docDb emulator local Uri. Uri docDbEmulatorUri = new Uri("https://codeslingerstour.documents.azure.com:443/"); //Fixed docDb emulator key const string docDbEmulatorKey = "YoZqHb6KfBGcx3icWUyUMghSqd7gJpScL5N6QexlXEDNe4GIxhBfnbtZQl71r0WtJol7OUxiOK6MeudWwubRcg=="; Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var store = new DocumentDbBotDataStore(docDbEmulatorUri, docDbEmulatorKey, "sfhack-autoscaler", "botstate"); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterWebApiFilterProvider(config); }); config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
protected void Application_Start(object sender, EventArgs e) { { //Using the local DocDbEmulator, which should be installed and started. Otherwise, edit the docDbEmulatorUri and docDbEmulatorKey variables to your DocDb database //Reference: https://docs.microsoft.com/en-us/azure/documentdb/documentdb-nosql-local-emulator //Fixed docDb emulator local Uri. Uri docDbEmulatorUri = new Uri("https://localhost:8081"); //Fixed docDb emulator key const string docDbEmulatorKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; var config = GlobalConfiguration.Configuration; Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var store = new DocumentDbBotDataStore(docDbEmulatorUri, docDbEmulatorKey); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterWebApiFilterProvider(config); }); config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container); } // WebApiConfig stuff GlobalConfiguration.Configure(config => { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }); }
protected void Application_Start() { // Bot Storage: This is a great spot to register the private state storage for your bot. // We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own! // For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var key = ConfigurationManager.AppSettings["DocumentDbKey"]; var store = new DocumentDbBotDataStore(uri, key, "departments", "FormData"); Conversation.UpdateContainer( builder => { 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(); }); //var store = new InMemoryDataStore(); //Conversation.UpdateContainer( // builder => // { // 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(); // }); GlobalConfiguration.Configure(WebApiConfig.Register); }
protected void Application_Start() { //GlobalConfiguration.Configure(WebApiConfig.Register); Uri docDbServiceEndpoint = new Uri(ConfigurationManager.AppSettings["DocumentDbServiceEndpoint"]); string docDbEmulatorKey = ConfigurationManager.AppSettings["DocumentDbAuthKey"]; var builder = new ContainerBuilder(); builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var store = new DocumentDbBotDataStore(docDbServiceEndpoint, docDbEmulatorKey); builder.Register(c => store).Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); builder.Update(Conversation.Container); GlobalConfiguration.Configure(WebApiConfig.Register); }
protected void Application_Start() { Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var key = ConfigurationManager.AppSettings["DocumentDbKey"]; var store = new DocumentDbBotDataStore(uri, key); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); }); GlobalConfiguration.Configure(WebApiConfig.Register); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var key = ConfigurationManager.AppSettings["DocumentDbKey"]; var store = new DocumentDbBotDataStore(uri, key); 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(); }
/// <summary> /// Logic required to start the application. /// </summary> protected void Application_Start() { RegisterContainer(); GlobalConfiguration.Configure(WebApiConfig.Register); using (ILifetimeScope scope = Container.BeginLifetimeScope()) { IBotProvider provider = scope.Resolve <IBotProvider>(); Task.Run(() => provider.InitializeAsync()).Wait(); ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = provider.Configuration.InstrumentationKey; Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); DocumentDbBotDataStore store = new DocumentDbBotDataStore( new Uri(provider.Configuration.CosmosDbEndpoint), provider.Configuration.CosmosDbAccessKey.ToUnsecureString()); builder.Register(c => { return(new MicrosoftAppCredentials( provider.Configuration.MicrosoftAppId, provider.Configuration.MicrosoftAppPassword.ToUnsecureString())); }).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(); }); } }
private static void SetupBotDataStore() { var uri = new Uri(ConfigurationManager.AppSettings["DocumentDbUrl"]); var key = ConfigurationManager.AppSettings["DocumentDbKey"]; var store = new DocumentDbBotDataStore(uri, key); Conversation.UpdateContainer( builder => { 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(); }); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); //Using the local DocDbEmulator, which should be installed and started. Otherwise, edit the docDbEmulatorUri and docDbEmulatorKey variables to your DocDb database //Reference: https://docs.microsoft.com/en-us/azure/documentdb/documentdb-nosql-local-emulator //Fixed docDb emulator local Uri. Uri docDbEmulatorUri = new Uri("https://localhost:8081"); //Fixed docDb emulator key const string docDbEmulatorKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; var globalConfig = GlobalConfiguration.Configuration; Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var store = new DocumentDbBotDataStore(docDbEmulatorUri, docDbEmulatorKey); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterWebApiFilterProvider(globalConfig); }); globalConfig.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container); var containerBuilder = new ContainerBuilder(); containerBuilder.Register <IHandler>(icc => new QuestionAndAnswerHandler()); containerBuilder.RegisterType <ActivityLogger>().AsImplementedInterfaces().InstancePerDependency(); containerBuilder.Update(Conversation.Container); }
protected void Application_Start() { // Bot Storage: This is a great spot to register the private state storage for your bot. // We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own! // For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure //load application settings. Settings.CosmosDBUri = SettingHelper.GetSetting("CosmosDBUri"); Settings.CosmosDBKey = SettingHelper.GetSetting("CosmosDBKey"); Settings.EnableCustomLog = Convert.ToBoolean(SettingHelper.GetSetting("EnableCustomLog")); Settings.EnableVerboseLog = Convert.ToBoolean(SettingHelper.GetSetting("EnableVerboseLog")); Settings.FunctionURL = SettingHelper.GetSetting("FunctionURL"); Settings.Cryptography = SettingHelper.GetSetting("Cryptography"); Settings.ImageStorageUrl = SettingHelper.GetSetting("ImageStorageUrl"); Settings.TranslatorKey = SettingHelper.GetSetting("TranslatorKey"); Settings.SpecificLanguage = SettingHelper.GetSetting("SpecificLanguage"); Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); // Using Azure Table Storage //var store = new TableBotDataStore(Settings.DataStorage); // requires Microsoft.BotBuilder.Azure Nuget package // To use CosmosDb or InMemory storage instead of the default table storage, uncomment the corresponding line below var store = new DocumentDbBotDataStore(new Uri(Settings.CosmosDBUri), Settings.CosmosDBKey, "AzureIntelligentHack", "Bot"); // requires Microsoft.BotBuilder.Azure Nuget package // var store = new InMemoryDataStore(); // volatile in-memory store builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); builder.RegisterType <TraceManager>().AsImplementedInterfaces().InstancePerDependency(); }); GlobalConfiguration.Configure(WebApiConfig.Register); }
protected void Application_Start() { Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); // Bot Storage: register state storage for your bot // Default store: volatile in-memory store - Only for prototyping! // var store = new InMemoryDataStore(); var uri = new Uri(ConfigurationManager.AppSettings["DocumentDBUri"]); var key = ConfigurationManager.AppSettings["DocumentDBKey"]; var store = new DocumentDbBotDataStore(uri, key); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); }); GlobalConfiguration.Configure(WebApiConfig.Register); }
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(); }
/// <inheritdoc/> protected override void Load(ContainerBuilder builder) { base.Load(builder); var configProvider = new LocalConfigProvider(); builder.Register(c => configProvider) .Keyed <IConfigProvider>(FiberModule.Key_DoNotSerialize) .AsImplementedInterfaces() .SingleInstance(); builder.Register(c => { return(new TelemetryClient(new TelemetryConfiguration(configProvider.GetSetting(CommonConfig.ApplicationInsightsInstrumentationKey)))); }).SingleInstance(); builder.RegisterType <UserManagementHelper>().SingleInstance(); builder.RegisterType <EventHelper>().SingleInstance(); // Override some Bot Framework registrations builder.Register(c => c.Resolve <IConnectorClientFactory>().MakeConnectorClient()) .Keyed <IConnectorClient>(FiberModule.Key_DoNotSerialize) // Tag IConnectorClient as DoNotSerialize .As <IConnectorClient>() .ExternallyOwned(); var appInsightsLogProvider = new AppInsightsLogProvider(configProvider); builder.Register(c => appInsightsLogProvider) .Keyed <ILogProvider>(FiberModule.Key_DoNotSerialize) .AsImplementedInterfaces() .SingleInstance(); var store = new DocumentDbBotDataStore( new Uri(configProvider.GetSetting(ApplicationConfig.CosmosDBEndpointUrl)), configProvider.GetSetting(ApplicationConfig.CosmosDBKey)); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); builder.Register(c => new CachingBotDataStore(store, CachingBotDataStoreConsistencyPolicy.LastWriteWins)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); // Register dialogs builder.RegisterType <RootDialog>() .AsSelf() .InstancePerDependency(); builder.RegisterType <DialogFactory>() .Keyed <DialogFactory>(FiberModule.Key_DoNotSerialize) .AsSelf() .InstancePerMatchingLifetimeScope(DialogModule.LifetimeScopeTag); builder.RegisterType <SkipEventDialog>() .AsSelf() .InstancePerDependency(); builder.RegisterType <ShareEventDialog>() .AsSelf() .InstancePerDependency(); builder.RegisterType <IgnoreEventShareDialog>() .AsSelf() .InstancePerDependency(); }
protected void Application_Start(object sender, EventArgs e) { { //Using the local DocDbEmulator, which should be installed and started. Otherwise, edit the docDbEmulatorUri and docDbEmulatorKey variables to your DocDb database //Reference: https://docs.microsoft.com/en-us/azure/documentdb/documentdb-nosql-local-emulator //Fixed docDb emulator local Uri. Uri docDbEmulatorUri = new Uri("https://localhost:8081"); //Fixed docDb emulator key const string docDbEmulatorKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; // http://docs.autofac.org/en/latest/integration/webapi.html#quick-start var builder = new ContainerBuilder(); // register the Bot Builder module builder.RegisterModule(new DialogModule()); // register the alarm dependencies builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); builder .RegisterInstance(new EchoDialog()) .As <IDialog <object> >(); var store = new DocumentDbBotDataStore(docDbEmulatorUri, docDbEmulatorKey); 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(); // Get your HttpConfiguration. var config = GlobalConfiguration.Configuration; // Register your Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); // OPTIONAL: Register the Autofac filter provider. builder.RegisterWebApiFilterProvider(config); // Set the dependency resolver to be Autofac. //var container = builder.Build(); builder.Update(Conversation.Container); config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container); } // WebApiConfig stuff GlobalConfiguration.Configure(config => { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }); }