From 34fc91f35dfbad56f8e1a662d036b3c6fd8355c0 Mon Sep 17 00:00:00 2001 From: Pablo Costantini Date: Tue, 13 Jun 2017 16:50:17 -0300 Subject: [PATCH] Replace ContainerBuilder.Update with Conversation.UpdateContainer --- CSharp/core-CustomState/Global.asax.cs | 18 ++++++------ .../core-GlobalMessageHandlers/Global.asax.cs | 12 ++++---- CSharp/core-Middleware/Global.asax.cs | 7 +++-- .../public-TestBot/Global.asax.cs | 27 +++++++++-------- .../demo-Search/JobListingBot/Global.asax.cs | 29 +++++++++---------- .../demo-Search/RealEstateBot/Global.asax.cs | 29 +++++++++---------- 6 files changed, 59 insertions(+), 63 deletions(-) diff --git a/CSharp/core-CustomState/Global.asax.cs b/CSharp/core-CustomState/Global.asax.cs index fc6e7d9910..f44451214d 100644 --- a/CSharp/core-CustomState/Global.asax.cs +++ b/CSharp/core-CustomState/Global.asax.cs @@ -17,17 +17,17 @@ protected void Application_Start() Uri docDbServiceEndpoint = new Uri(ConfigurationManager.AppSettings["DocumentDbServiceEndpoint"]); string docDbEmulatorKey = ConfigurationManager.AppSettings["DocumentDbAuthKey"]; - var builder = new ContainerBuilder(); + Conversation.UpdateContainer(builder => + { + builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); - builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); + var store = new DocumentDbBotDataStore(docDbServiceEndpoint, docDbEmulatorKey); + builder.Register(c => store) + .Keyed>(AzureModule.Key_DataStore) + .AsSelf() + .SingleInstance(); - var store = new DocumentDbBotDataStore(docDbServiceEndpoint, docDbEmulatorKey); - builder.Register(c => store) - .Keyed>(AzureModule.Key_DataStore) - .AsSelf() - .SingleInstance(); - - builder.Update(Conversation.Container); + }); GlobalConfiguration.Configure(WebApiConfig.Register); } diff --git a/CSharp/core-GlobalMessageHandlers/Global.asax.cs b/CSharp/core-GlobalMessageHandlers/Global.asax.cs index 1a0e02e037..138a0e5c6d 100644 --- a/CSharp/core-GlobalMessageHandlers/Global.asax.cs +++ b/CSharp/core-GlobalMessageHandlers/Global.asax.cs @@ -16,13 +16,11 @@ protected void Application_Start() private void RegisterBotModules() { - var builder = new ContainerBuilder(); - - builder.RegisterModule(new ReflectionSurrogateModule()); - - builder.RegisterModule(); - - builder.Update(Conversation.Container); + Conversation.UpdateContainer(builder => + { + builder.RegisterModule(new ReflectionSurrogateModule()); + builder.RegisterModule(); + }); } } } diff --git a/CSharp/core-Middleware/Global.asax.cs b/CSharp/core-Middleware/Global.asax.cs index 946ef8d110..c15750cd38 100644 --- a/CSharp/core-Middleware/Global.asax.cs +++ b/CSharp/core-Middleware/Global.asax.cs @@ -8,9 +8,10 @@ public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { - var builder = new ContainerBuilder(); - builder.RegisterType().AsImplementedInterfaces().InstancePerDependency(); - builder.Update(Conversation.Container); + Conversation.UpdateContainer(builder => + { + builder.RegisterType().AsImplementedInterfaces().InstancePerDependency(); + }); GlobalConfiguration.Configure(WebApiConfig.Register); } diff --git a/CSharp/demo-CardsAttachments/public-TestBot/Global.asax.cs b/CSharp/demo-CardsAttachments/public-TestBot/Global.asax.cs index e7d45fc5d3..0c5a7f99fb 100644 --- a/CSharp/demo-CardsAttachments/public-TestBot/Global.asax.cs +++ b/CSharp/demo-CardsAttachments/public-TestBot/Global.asax.cs @@ -21,23 +21,22 @@ protected void Application_Start() private void RegisterBotDependencies() { - var builder = new ContainerBuilder(); - - builder - .Register(c => new ActivityLogger(c.Resolve())) - .As() - .InstancePerLifetimeScope(); - - foreach (var commandType in CommandsHelper.GetRegistrableTypes()) + Conversation.UpdateContainer(builder => { builder - .RegisterType(commandType) - .Keyed(commandType.Name, commandType) - .AsImplementedInterfaces() - .InstancePerMatchingLifetimeScope(DialogModule.LifetimeScopeTag); - } + .Register(c => new ActivityLogger(c.Resolve())) + .As() + .InstancePerLifetimeScope(); - builder.Update(Conversation.Container); + foreach (var commandType in CommandsHelper.GetRegistrableTypes()) + { + builder + .RegisterType(commandType) + .Keyed(commandType.Name, commandType) + .AsImplementedInterfaces() + .InstancePerMatchingLifetimeScope(DialogModule.LifetimeScopeTag); + } + }); } } } \ No newline at end of file diff --git a/CSharp/demo-Search/JobListingBot/Global.asax.cs b/CSharp/demo-Search/JobListingBot/Global.asax.cs index 99323d63fe..abccc623a9 100644 --- a/CSharp/demo-Search/JobListingBot/Global.asax.cs +++ b/CSharp/demo-Search/JobListingBot/Global.asax.cs @@ -14,23 +14,22 @@ public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { - ContainerBuilder builder = new ContainerBuilder(); + Conversation.UpdateContainer(builder => + { + builder.RegisterType() + .As>() + .InstancePerDependency(); - builder.RegisterType() - .As>() - .InstancePerDependency(); + builder.RegisterType() + .Keyed>(FiberModule.Key_DoNotSerialize) + .AsImplementedInterfaces() + .SingleInstance(); - builder.RegisterType() - .Keyed>(FiberModule.Key_DoNotSerialize) - .AsImplementedInterfaces() - .SingleInstance(); - - builder.RegisterType() - .Keyed(FiberModule.Key_DoNotSerialize) - .AsImplementedInterfaces() - .SingleInstance(); - - builder.Update(Conversation.Container); + builder.RegisterType() + .Keyed(FiberModule.Key_DoNotSerialize) + .AsImplementedInterfaces() + .SingleInstance(); + }); GlobalConfiguration.Configure(WebApiConfig.Register); } diff --git a/CSharp/demo-Search/RealEstateBot/Global.asax.cs b/CSharp/demo-Search/RealEstateBot/Global.asax.cs index c52e29096a..176d3d9aea 100644 --- a/CSharp/demo-Search/RealEstateBot/Global.asax.cs +++ b/CSharp/demo-Search/RealEstateBot/Global.asax.cs @@ -15,23 +15,22 @@ public class WebApiApplication : HttpApplication { protected void Application_Start() { - ContainerBuilder builder = new ContainerBuilder(); + Conversation.UpdateContainer(builder => + { + builder.RegisterType() + .As>() + .InstancePerDependency(); - builder.RegisterType() - .As>() - .InstancePerDependency(); + builder.RegisterType() + .Keyed>(FiberModule.Key_DoNotSerialize) + .AsImplementedInterfaces() + .SingleInstance(); - builder.RegisterType() - .Keyed>(FiberModule.Key_DoNotSerialize) - .AsImplementedInterfaces() - .SingleInstance(); - - builder.RegisterType() - .Keyed(FiberModule.Key_DoNotSerialize) - .AsImplementedInterfaces() - .SingleInstance(); - - builder.Update(Conversation.Container); + builder.RegisterType() + .Keyed(FiberModule.Key_DoNotSerialize) + .AsImplementedInterfaces() + .SingleInstance(); + }); GlobalConfiguration.Configure(WebApiConfig.Register); }