应用程序外观模式的最佳实践(Best practice for application facade pattern)
我有一个多层SOA应用程序和一个包含100多个表的数据库。 我正在为我的数据层使用实体框架来处理所有CRUD操作。
我有一个门面类,它托管在一个服务上,可以通过全部客户端应用程序调用。
这个facade类包含诸如的方法
private void DoSomething() { //insert to table1 //insert to table 2 //delete from table 3 //more CRUD operations }
而且Facade类基本上已经充满了类似于DoSomething()的其他方法。
因此,客户端基本上将创建Facade类的实例,并获得对所有这些方法的访问权限。
我现在的问题是,这是门面图案的最佳做法吗? 我觉得门面类太“重”了,如果我的应用程序扩展得更大,我不确定它是否会影响性能。
如果我有大量的方法,那么创建一个facade类的实例是一个非常昂贵的操作吗?
I have a multi tiered SOA application and a database with over 100 tables. I'm using entity framework for my data layer which takes care of all CRUD operations.
I have 1 facade class which is hosted on a service, callable by client apps all over.
This facade class contains methods such as
private void DoSomething() { //insert to table1 //insert to table 2 //delete from table 3 //more CRUD operations }
And the facade class is basically full with loads of other methods similar to DoSomething()
So the client will basically create an instance of the facade class, and gain access to all these methods.
My question now is, is this the best practice for a facade pattern? I feel that the facade class is way too "heavy" and I'm not sure if it will affect the performance if my application scales bigger.
Will creating an instance of the facade class be a very expensive operation if I have loads of methods in it?
原文:https://stackoverflow.com/questions/12738819
最满意答案
您可以查看Mongoose 虚拟机 ,这些虚拟机是您可以获取和设置但不会持久保存到数据库的属性:
Game.schema.virtual('won').get(function() { return this.result === 'Won' })
http://mongoosejs.com/docs/guide.html#virtuals
如果您只想在模板中使用它,那么您还可以在视图中的本地人身上设置特定属性。
也许是这样的:
... exports = module.exports = function(req, res) { var view = new keystone.View(req, res) var locals = res.locals locals.games = [] view.on('init', function(next) { var query = {} // Add query here Game.model.find(query).exec(function(err, games) { // Handle error games.forEach(function(game) { game.won = game.result === 'Won' }) locals.games = games }) }) } ...
You could look at Mongoose virtuals which are properties that you can get and set but that do not get persisted to the database:
Game.schema.virtual('won').get(function() { return this.result === 'Won' })
http://mongoosejs.com/docs/guide.html#virtuals
If you just want to use it in your template then you could also set a specific property on locals in your view.
Perhaps something like this:
... exports = module.exports = function(req, res) { var view = new keystone.View(req, res) var locals = res.locals locals.games = [] view.on('init', function(next) { var query = {} // Add query here Game.model.find(query).exec(function(err, games) { // Handle error games.forEach(function(game) { game.won = game.result === 'Won' }) locals.games = games }) }) } ...
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
事实证明我对view.query的原始更改是正确的。 我只需要重新启动我的数据库。 Turns out that my original change with view.query was correct. I just needed to restart my database.
-
安装后运行'npm keystone'时的Keystone错误(Keystone error when running 'npm keystone' after installation)[2023-12-15]
这是错误消息的重要部分: Mongo Error: [Error: failed to connect to [localhost:27017]] Keystone无法连接到您的数据库,您也可以通过在终端中运行以下命令来确认: mongo localhost:27017 很难说出具体原因,但您应该查看相关文档以在OS X上安装MongoDB Community Edition 。 This is the important part of the error message: Mongo Error: ... -
如何更改keystone端口#?(How to change keystone port#?)[2023-11-18]
Keystone使用port设置,该设置回退到process.env.PORT , process.env.OPENSHIFT_NODEJS_PORT ,最终返回3000 。 您可以通过多种方式更改此设置,方法是在keystone.js文件中设置port ,如下所示: keystone.init({ name: 'My App', brand: 'My App', port: 3010 //... }); 要么 keystone.set('port', 3010); 或者 ... -
修复此问题,确保所有节点模块都在服务器上,使用sourcetree保持超时推送到repo,因此模块不在那里。 我代替他们FTP了。 Fixed this by making sure all node modules were on the server, pushing to the repo using sourcetree kept timing out, so the modules weren't there. I FTP'd them instead.
-
注释掉的代码声明了keystone_user类型的资源 ,而不是类。 据推测,它的类型keystone_user由puppet-keystone模块提供。 include()系列函数用于声明类,而不是资源,因此它们不适用于keystone_user 。 您可以通过多种方式继续进行。 如果你没有想到比声明一个或多个keystone_user更复杂的东西,那么我建议给你的类一个用户名的参数,你可以通过Hiera为其分配一个值: class kilo2_keystone($usernames = []) { ...
-
Keystone和Cloudinary(Keystone and Cloudinary)[2024-03-16]
显然keystone无法弄清楚我的网络的代理设置,因此连接到不同的网络修复此问题 apparently keystone could not figure out my network's proxy settings so connecting to a different network fixed this -
您可以查看Mongoose 虚拟机 ,这些虚拟机是您可以获取和设置但不会持久保存到数据库的属性: Game.schema.virtual('won').get(function() { return this.result === 'Won' }) http://mongoosejs.com/docs/guide.html#virtuals 如果您只想在模板中使用它,那么您还可以在视图中的本地人身上设置特定属性。 也许是这样的: ... exports = module.exports = func ...
-
目前,WireCloud仅在使用wirecloud.fiwarelabtheme主题时从IdM服务器注销。 此外,您必须编辑FIWARE_PORTALS设置并覆盖Account门户的定义(并可能删除其他门户)。 我已经创建了一张修复此问题的票 。 这是FIWARE_PORTALS设置的默认值: FIWARE_PORTALS = ( {'name': 'Cloud', 'url': 'https://cloud.lab.fiware.org', "logout_path": "/logout"}, ...
-
我认为问题与KeystoneJS内部处理Types.Name字段类型的方式有关。 在您的jade文件中,您应该使用其虚拟name.full属性的路径引用您的name字段。 在内部, name.full有一个setter,它将name拆分为name.first和name.last 。 因此,如果您希望为名字和姓氏分别input ,则应使用name.first和name.last 。 如果您想要input单个input的全名,则应使用name.full 。 尝试替换名称字段的input控件: input.for ...