Search code examples
azureazure-configuration

Is this how to set Context Connection String Using CloudConfigurationManager?


I am looking to use CloudConfigurationManager so I can take advantage of Azure configuration files. I want to use a connection string I added a string to my Cloud.cscfg to configure Entity Framework Context.

I was configuring my context like this

public DomainContext()
    : base("ContextConnectionString")

This was taking the ContextConnectionString from the Web.config

I changed the Context Constructor to this

public DomainContext()
    : base(CloudConfigurationManager.GetSetting("ContextConnectionString"))

And it now works.

Is there a more elegant way to tell my context constructor to use Azure cscfg first?


Solution

  • There is not a more elegant solution at the moment, no. In fact this is quite a bit more elegant than what you would have had to have written a month ago. The CloudConfigurationManager is a class that is new in the 1.7 SDK and was created because previously there was no built in support for doing this sort of thing. If you wanted to do what CloudConfigurationMangager does now you had to create your own class, which was pretty common.