从单一的服务和模型层的多个网站 [英] Multiple websites from a single service and model layer

查看:99
本文介绍了从单一的服务和模型层的多个网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做类似stackexchange但有自己的域名的东西。我想有1单一的数据库,资料库/模型层,服务层1的服务器上。然后,一个不同的服务器或同一台服务器上,我有可以访问这些层的Web项目。

有没有办法实现这一目标而不在这些网站上的表现一炮打响?我想只是提供一个WCF服务,但与发电和读取XML,它似乎慢。我可以做到这一点有什么其他办法?

这是什么stackexchange办?


这是什么,我想完成一个简单的架构:

每个其他UI可以或可以不具有自己的数据库。

我的目标是:

我要为我们一组人来开发网站提供一系列的服务。我想所有这些相关数据在一个数据库中。但每一个可能需要单独的逻辑/数据库。我想在每个站点,每个用户都有自己的身份验证。我也想我的服务层来区分哪个域从传来的请求。


解决方案

  

    

有没有办法实现这一目标而性能命中在这些网站?


  

在网站?难道你的意思是在共享服务?

您在解析XML地段的是完全正确的将是缓慢的,但WCF能够以不同的方式进行绑定,这样你就不会明确地绑在解析XML。

更一般地,如果你注意到的表现:


  • 都部署到同一个服务器 - 保存自己跳越过网络

  • 请不要远程连接直接去找。使用依赖注入动态加载了一个供应商,所以你仍然可以管理的依赖关系。另外分拆是,你code将执行同一过程,所以你甚至不会有跨进程跳。

  • 考虑缓存。

这只是从我的头顶,我还建议通过标签搜索计算器 - 特别是性能标签并且把你看中的其他任何<一个href=\"http://stackoverflow.com/questions/tagged/performance+.net\">http://stackoverflow.com/questions/tagged/performance+.net

修改:哦,我差点忘了:它还听起来好像你进入多租户;你可能想看看:

我包括数据架构一个作为你所提到的数据库不可小视,这可能会给你一些很好的精神食粮。

修改


  

    

我还是不明白我怎么会上传一个新的Web项目,将利用主系统使用相同的过程。


  

同样的工艺或相同的功能/数据?

我猜这是你想要重新使用(用方法我想你的意思执行相同的物理过程)的功能和数据;在这种情况下很容易 - 让一个组件和部署/使用它很多次

让我们说你的共享服务是一个数据库,关于,也就是一些.NET组件执行实际的数据访问坐着的,这暴露了某种接口/ API的。

选项1:直接消耗


  • 所需的DLL复制到新的WEP的应用程序

  • 添加必要的配置,参考服务管理code。

  • 让您的BL code直接使用服务的API。

  • 新系统:重复

在这里,你有一个组成部分,但它的多个实例 - 每个Web应用程序

优点:


  • 要快速设置,假设服务已经可以使用的API,并在所讨论的是部署的状态。

缺点:


  • 您已经'硬codeD自己一个dependencey;如果你这样做是为了多个项目你就会有一个恶梦进行更改(例如)服务的基础数据 - 因为它会影响到所有的web应用程序谁使用它

  • 您的核心BL code直接消耗的外部组件,这code将通过你的BL散 - 求你不需要做显著的变化

选项2:适配器


  • 同方法1,只是你的BL code没有引用服务,也不是code直接使用服务API;而不是建立一个新包,做这一切为你(项目/组装),然后有BL经过这一点。

优点:


  • 不太一样邪恶选项1,你现在有自己的核心系统code和服务之间一定程度的隔离。

缺点:


  • 同为1的选项,除了你的code是非常干净多了。

选项3:<一href=\"http://www.morphological.geek.nz/blogs/viewpost/Peruse+Muse+Infuse/An+Introduction+to+Dependency+Inversion.aspx\"相对=nofollow>依赖倒置(DI)


  • 要选择2类似,但该适配器现在是一个抽象接口和网络应用程序不直接引用服务;他们会引用包含接口的组件 - 但那是pretty太多所有组件将举行。

  • 您可能会最终也规定该系统使用的常见类型共同组装 - 通常被称为普通老式C#对象(PO​​CO的)

  • 的想法是,接口和POCO assebilies不会有太大变化(见稳定依赖原则和抽象稳定的原则,无论是上面链接的DI文章中提到的)

  • 的接口需要通过两侧被引用但由服务资 - 这样的服务定义它。当你在设计的服务,您可以显然仍与Web应用程序的考虑的具体需求设计它。

优点:


  • 完全分离==更好的依赖管理。

  • 通过一个定义良好的接口,更方便的再利用。

缺点:


  • 无真(?)

  • 这可能需要更多thinkingon您的一部分,更多的努力来得到这个设置,但一旦你在那里你会在一个更好的基础,因此它会还清。

I want to do something similar to stackexchange but with their own domain. I want to have 1 single database, repository/model layer, service layer on 1 server. Then on a different server or same server, I have a web project which can access those layers.

Is there a way to achieve this without a hit in performance on these sites? I'm thinking about just providing a WCF service, but with that generating and reading xml, it seems slow. What other way may I accomplish this?

What does stackexchange do?


This is a simple architecture of what I want to accomplish:

Each other UI may or may not have their own Database.

My goal is:

I want to provide a set of service for sites we'll be developing for a set of people. I want all of these relevant data in a single database. But each one may need separate logic/database. I'd like each user on each site to have their own authentication. I also would like my service layer to differentiate which domain the request it coming from.

解决方案

Is there a way to achieve this without a hit in performance on these sites?

On the sites? Don't you mean on the shared Service?

You're quite correct in that parsing lots of XML will be slow, but WCF can bind in different ways, so you aren't explicitly tied to parsing XML.

More generally, if you're mindful of performance:

  • Deploy everything onto the same server - save yourself a hop cross the network.
  • Don't connect remotely go direct. Use Dependency Injection to load up a provider dynamically, so you can still manage dependencies. Another spin-off is that you're code will execute on the same process so you won't even have to hop across processes.
  • Consider caching.

This is just off the top of my head, I'd also suggest searching StackOverFlow by tag - specifically the performance tag and any others that take your fancy: http://stackoverflow.com/questions/tagged/performance+.net

Edit: Oh, I almost forgot: It also sounds like you're getting into Multitenancy; you might want to check out:

I included the data architecture one as you mentioned databases quite a lot, this might give you some good food for thought.

Edit:

I still dont understand how I would upload a new web project that will utilise the same process that the main system is using

Same process or same functionality / data?

I'm guessing it's the functionality and data you want to re-use (by process I thought you meant same physical process of execution); in which case it's easy - make one component and deploy/use it many times.

Lets say your shared service is a database, and sitting "on" that is some .Net component that does the actual data access, and which exposes some sort of interface / API.

Options 1: Direct Consumption

  • Copy the necessary DLL's into your new wep app
  • add the necessary config, reference the services managed code.
  • Have your BL code directly use the service API.
  • New system: repeat.

Here you have one component but multiple instances of it - one for each web app.

Pros:

  • Fast to set-up, assuming the service already has an API you can use and is in a state that is deployable as discussed.

Cons:

  • You've 'hard-coded' yourself to a dependencey; and if you do it to multiple projects you'll have a nightmare making changes to the service's underlying data (for example) - because it'll affect all the web apps who consume it.
  • You core BL code directly consumes an external component, this code will be scattered all through your BL - pray you don't need to make significant changes.

Option 2: Adapter

  • Same as Option 1 except that your BL code doesn't reference the service, nor does it's code directly use the service API; instead make a new package (project/assembly) that does all of this for you, then have the BL go through that.

Pros:

  • Not quite as evil as option 1, you now have some degree of isolation between your core system code and the service.

Cons:

  • The same as option 1, except your code is much much cleaner.

Option 3: Dependency Inversion (DI)

  • Similar to option 2, except the adapter is now an abstract interface and the web-apps don't reference the service directly; they will reference the assembly that contains the interfaces - but that's pretty much all that assembly will hold.
  • You'll probably end up also defining a common assembly that has common types used by your system - commonly known as Plain Old C# Objects (POCO's).
  • The idea is that the interfaces and POCO assebilies won't change much (see the Stable Dependencies Principle and Stable Abstractions Principle, both are referred to in the DI article linked above)
  • The interface needs to be referenced by both "sides" but is owned by the service - so the service defines it. When you're designing the service you can obviously still design it with the specific needs of your web apps in mind.

Pros:

  • Complete separation == better dependency management.
  • Easier re-use via a well defined interface.

Cons:

  • None really (?)
  • It might take more thinkingon your part and more effort to get this set-up, but once you're there you'll be on a much better footing, and so it will pay off.

这篇关于从单一的服务和模型层的多个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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