Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin architecture #561

Open
ngocdaothanh opened this issue Jul 31, 2015 · 8 comments
Open

Add plugin architecture #561

ngocdaothanh opened this issue Jul 31, 2015 · 8 comments
Assignees
Labels
Milestone

Comments

@ngocdaothanh
Copy link
Member

The purpose is to be able to move Swagger etc. out of Xitrum core, to xitrum-swagger plugin etc. This way we can develop/upgrade plugins independently from Xitrum core.

We need to design an entry point to let plugins initialize themselves during Xitrum startup. We may require that a plugin provides an empty constructor. During startup, Xitrum will create an instance of the specified plugin class.

Plugins are included via build.sbt and their classes are specified in config/xitrum.conf file like this:

plugins = [xitrum.Swagger, xitrum.Scalate]

We need to design when to load plugins, so that plugin creators know when their plugins will be loaded, so that they can design their plugins properly.

@ngocdaothanh ngocdaothanh self-assigned this Jul 31, 2015
@ngocdaothanh ngocdaothanh added this to the Xitrum 3.25.0 milestone Jul 31, 2015
@caiiiycuk
Copy link
Contributor

It wil be great if plugins can be included by direct github url, for example:

plugins = [ https://github.com/caiiiycuk/xitrum-memcached ]

Or if we need concrete version:

plugins = [ https://github.com/caiiiycuk/xitrum-memcached#v1.0 ]

@caiiiycuk
Copy link
Contributor

Recently i wanted to write plugins for database and for dependency injection. Both plugins need to inject something in Action object. I understand that for implementing this plugins in nice way, xitrum should provide some api to listen/control life cycle of Action.

For example DI plugin (based on google guice):

Client code:

class MyAction extends Action {

  @Inject
  private var connection: Connection;

  @Inject
  private var resource: Resource;

...
}

Plugin implementation:

...
  def decorateAction(action: Action): Action = {
      injector.inject(action)
      action
  }
...

@ngocdaothanh
Copy link
Member Author

plugins can be included by direct github url

I think it's better to let SBT manage the plugins.
Plugins should be just normal libraries
and can be specify in, for example, build.sbt.
It is better this way, because your plugins can include other libraries,
and SBT can easily manage the dependencies.

You can tell SBT to load a project from GitHub:
http://stackoverflow.com/questions/7550376/how-can-sbt-pull-dependency-artifacts-from-git

inject something in Action object

So now we have some hook points in our plan:

Action:

  • When action instance is created.
  • When action is run (similar to before/after filter).

Server:

  • When routes are collected.
  • When server is started.
  • When server is stopped.

If you have ideas about more hook points, please share.

@ngocdaothanh
Copy link
Member Author

About config:

I think conceptually, config files in the config directory (xitrum.conf, for example) should only expose things that should be tuned manually when deploying to an environment (production server, for example).

In this direction, I think:

  • Plugins should also be able to be wired inside source code (Boot.scala, for example), not only in textual config files. Wiring in config files is for optional plugins that can be turned on/off when deploying. Wiring in source code is more typesafe, for non-optional plugins.
  • If a plugin need to be tuned manually more, it can add its own config files (and included in application.conf), or inlined to xitrum.conf for convenience.

@ngocdaothanh
Copy link
Member Author

What plugins to create:

For now, we plan to move these from Xitrum core to outside plugins (please comment if I miss something):

  • Scalate
  • Swagger
  • Metrics

@georgeOsdDev
Copy link
Member

  • SockJS
    I think it can be export like xitrum-framework/xitrum-ko
  • Xitrum-JS(jQuery and jQuery-Validation)
    In some cases that do not require jQuery in recent JS project.
  • FileMonitor

BTW, In PlayFramework, we can use plugin(module) like this.

In plugins.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.8")

In build.sbt

libraryDependencies += ws

In application code

import play.api.libs.ws._

@caiiiycuk
Copy link
Contributor

Also needed plugins that controls session. For example session store in memcached, database, etc.

@caiiiycuk
Copy link
Contributor

Xitrum-JS(jQuery and jQuery-Validation)
In some cases that do not require jQuery in recent JS project.

+1, we use AngularJS. So, jquery is redundant for us.

@ngocdaothanh ngocdaothanh modified the milestones: Xitrum 3.25.1, Xitrum 3.25.0 Aug 13, 2015
@ngocdaothanh ngocdaothanh modified the milestones: Xitrum 3.29.0, Xitrum 3.28.1 Oct 2, 2016
@ngocdaothanh ngocdaothanh modified the milestones: Xitrum 3.29.0, Xitrum 4.0.0 May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants