这是开始横跨复式MVC应用程序共享代码以适当的方式? [英] Is this an appropriate way to start sharing code across mutliple mvc apps?

查看:105
本文介绍了这是开始横跨复式MVC应用程序共享代码以适当的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为同一家公司的多个应用程序。

We are developing multiple applications for the same company.

该应用程序是不同的(所以不适合多坦南特应用程序),但会有很多共享的车型,一对夫妇共享控制器和理想的一些共享的看法。

The applications are distinct (so not suitable for a multi-tennant app) but there will be lots of shared models, a couple of shared controllers and ideally some shared views.

这是我第一次不得不这样做,并想知道如果我正确地接近它。这是我的计划:

It is the first time I have had to do this, and wonder if I am approaching it correctly. Here is my plan:


  • 创建数据库为共享的东西,另一个(每个应用程序)应用具体的东西

  • Create a DB for the shared stuff, and another (per application) for application specific stuff

每个应用程序将在Web配置2个连接

Each application will have 2 connections in web config

创建共享的车型DLL和控制器。把这个在/ bin目录,并在项目中引用它。我想这近似的NuGet包可能的工作方式,并引用

Create a DLL from the shared models and controllers. Put this in the /bin directory and reference it in the project. I want this to approximate the way a nuget package might work, and reference the

对于每个应用程序创建一个 SharedApplicationDBContext LocalApplicationDBContext ,每个接入相应的DB。

For each app create a SharedApplicationDBContext and a LocalApplicationDBContext, each accessing the respective DB.

问题


  • 是以上步骤是正确的是采取?

  • Are the above steps the right ones to be taking?

有什么办法,包括在一个DLL CSHTML看法?

Is there any way to include cshtml Views in a DLL?

它是确定为包括用户控制器/型号的DLL?

Is it ok to include the Users controller / models in the DLL?

是否有任何陷阱我应该知道了复式应用这样的共享代码的时候?

Are there any gotchas I should be aware of when sharing code like this over mutliple apps?

我就知道这么喜欢具体的问题,这是一个有点模糊,但我有点不在我的深度这里寻找一些一般性指导,以正确的方法来。采取

I know SO likes specific questions, and this is a bit vague, but I'm a bit out of my depth here and looking for some general guidance as to the right approach to take.

推荐答案

您已经得到了总体思路,但它需要一些调整:

You've got the general idea, but it needs some tweaking:


  1. 不要的DLL鬼混。如果在同一个解决方案中存在的项目,那你还不如让你的类库有作为。在这种情况下,你可以做直项目引用。如果你处理的多种解决方案,那么你打包类库作为的NuGet包,实际上它在每个项目中安装。创建的NuGet包很容易的,你既可以的从本地/网络路径安装或你可以建立自己的私人的NuGet回购。这使得它愣神容易共享资源,你到发布更新,看看在哪些项目正在运行的类库的哪个版本一目了然的能力。

  1. Don't fool around with DLLs. If the projects exist in the same solution, then you might as well keep your class library there as well. In which case, you can just do a straight project reference. If you're dealing with multiple solutions then you package your class library as a nuget package and actually install it in each project. Creating a nuget package is easy enough, and you can either install from a local/network path or you can set up your own private nuget repo. This makes it stupidly easy to share resources, and you get the ability to publish updates and see at a glance which projects are running which versions of your class library.

每个应用程序应该只涉及到它的各个数据库的上下文。共享数据库也可以使用共享的上下文,这将是中包含的类库。你也应该容纳所有涉及到在同一个类库这种共享环境的迁移。

Each app should only have the context that relates to its individual database. The shared database can also use a shared context, which would be contained in your class library. You should also house all your migrations related to this shared context in the same class library.

您可以包括意见类库,而不是作为CSHTML。他们必须被编译成类库。你需要 RazorGenerator 来做到这一点。

You can include views in a class library, but not as cshtml. They have to be compiled into the class library. You'll need RazorGenerator to accomplish this.

这是100%好了,包括你的共享库与用户的机型。但是,控制器是棘手。除非你设置SSO服务器,将单独负责处理所有的认证(一个不平凡的任务,至少可以说),每个应用程序都需要它是身份验证任务自己的控制器。如果所有的网站将驻留在同一个域或它们的子域,您可以轻松地共享它们之间的AUTH的cookie。但是,如果他们将驻留在完全不同的领域,你仍然可以共享相同的用户,凭借用每个相同的数据库,但每个站点都需要一个单独的登录过程(在同一登录不记录您在在另一个,即使相同的凭证将两个工作)。围绕着唯一的办法是,再次SSO。

It's 100% okay to include the models related to users in your shared library. However, the controller is trickier. Unless you set up an SSO server that will alone be responsible for handling all authentication (a non-trivial task to say the least), each application will need it's own controller for authentication tasks. If all of the sites will reside on the same domain or subdomains thereof, you can easily share the auth cookie between them. However, if they will reside on entirely different domains, you can still share the same "users", by virtue of using the same database for each, but each site will require a separate login process (logging in at one does not log you in at another, even though the same credentials would work for both). The only way around that is, again, SSO.

这篇关于这是开始横跨复式MVC应用程序共享代码以适当的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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