如何不同的MVC网站之间共享模式? [英] How to share models between different MVC websites?

查看:126
本文介绍了如何不同的MVC网站之间共享模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的ASP.NET MVC 3网站2个独立的领域 - 管理(内部网站)和客户端(互联网网站)

该模型(业务和数据访问层)将通过这两个网站的使用。该网站将在单独的服务器上托管。因此,该文件夹将不被共享。
所以,我打算创建模型的DLL,把DLL在这两个网站的bin文件夹并使用它。

我希望这将让我的用户界面简洁,少code为好。

现在,我的疑惑是:


  1. 请我需要创建一个类库项目创建模型的DLL或做我需要使用和MVC Web应用程序项目创建DLL?

  2. 我在哪里应该把web配置?希望我需要在这两个模型,也是在UI?


解决方案

是的,你的抽象的业务逻辑应该是在一个单独的类库项目。然后,您可以从Web应用程序在同一个解决方案引用该项目或编译,并引用它作为一个DLL。你的web.config文件(S)将仍然住在你的web项目(S)。

要在Web项目中为你的类库中添加的设置,使用的配置部分:

 < configSections>
    < sectionGroup名=的applicationSettingsTYPE =System.Configuration.ApplicationSettingsGroup,系统,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089>
        <节名称=My.Class.Library.Properties.SettingsTYPE =System.Configuration.ClientSettingsSection,系统,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089requirePermission =FALSE/>
    < / sectionGroup>
< / configSections>
<&的applicationSettings GT;
    < My.Class.Library.Properties.Settings>
        <设定名=SettingNameserializeAs =字符串>
            < VALUE> SettingValue< /值>
        < /设置>
    < /My.Class.Library.Properties.Settings>
< /&的applicationSettings GT;

I have 2 seperate areas for my ASP.NET MVC 3 website - Admin (Intranet website) and Client (Internet website).

The Model (business and data access layer) will be used by both websites. The websites will be hosted on seperate servers. So, the folder will not be shared. So, I am planning to create the DLL of the Model and put the DLL in the Bin Folder of both website and use it.

I hope this will keep my UI neat and less code as well.

Now, my doubts are:

  1. Do I need to create a Class Library project to create the DLL of the Model or do I need to use and MVC web application project to create the DLL?
  2. Where should I put the web config? Hope I need in both Model and also in UI?

解决方案

Yes, your abstracted business logic should be in a separate class library project. You can then reference this project from web apps in the same solution or compile it and reference it as a DLL. Your web.config file(s) will still live in your web project(s).

To add settings for your class library in your web project, use configuration sections:

<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="My.Class.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
</configSections>
<applicationSettings>
    <My.Class.Library.Properties.Settings>
        <setting name="SettingName" serializeAs="String">
            <value>SettingValue</value>
        </setting>
    </My.Class.Library.Properties.Settings>
</applicationSettings>

这篇关于如何不同的MVC网站之间共享模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆