【问题标题】:Where to configure Azure table storage settings in MVC 4 Web API project?在 MVC 4 Web API 项目中在哪里配置 Azure 表存储设置?
【发布时间】:2013-10-04 17:35:47
【问题描述】:

基于 MVC 4 Web API 模板处理一个简单的(我的第一个)Azure Web 角色,并试图弄清楚如何组织我的 Azure 表存储连接设置。

我可以在控制器 POST 处理程序中成功写入我的 Azure 表存储,如下所示:

    public void Post([FromUri]string param1, [FromUri]string param2)
    {


        MyEntity myEntity = new MyEntity();

        <do stuff to set up entity>
        ...

        // Entity is ready to insert

        // ** Question: Where should I set this Table settings?  Don't want to construct it with each POST right?
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("PushEventTable");
        TableOperation insertOperation = TableOperation.Insert(myEntity);

        // Execute the insert operation.
        table.Execute(insertOperation);

    }

我的问题是:管理表连接信息(或我可能在控制器中使用的其他全局变量)的最佳做法是什么? Web 角色的范围内应该在哪里进行全局配置设置和像这些 ONCE 这样的对象,以便所有控制器都可以访问它们?

【问题讨论】:

  • 我建议不要在控制器中这样做,而是使用存储库模式。

标签: c# asp.net-mvc-4 azure azure-table-storage


【解决方案1】:

这是一个很好的做法,将代码分层。

看看 DDD(基础设施部分) http://www.codeproject.com/Articles/56767/Domain-Driven-Design

并像 Gaurav 所说的那样使用存储库。

【讨论】:

    猜你喜欢
    • 2020-10-11
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2012-04-16
    • 2011-07-10
    相关资源
    最近更新 更多