Load controllers dynamically

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Load controllers dynamically

Sergei Rahouski

Hi all,

 

We need to add a way to dynamically change certain parts of the application based on customer. The customer number is determined on the startup and never changes during the application life time.

 

Based on the customer we would like to replace controllers with customized versions of controllers, replace views and services too.

 

I’ve played with Grails plugin architecture a bit and it looked promising but it would take weeks to get our application to play nice with it. Plus it is not entirely clear how to dynamically load plugins based on a setting.

 

Short term I would like to be able to program customization logic myself by creating a folder structure like this:

 

grails-app

    customers

       customer1

            controllers

            services

            src

            views

            resources.groovy

       customer2

          controllers

         services

         src

          views

          resources.groovy

 

I am pretty clear on how to load additional services at runtime and how to make them override existing. Controllers though are not as straightforward because Grails does a bunch of stuff to make them useful.

 

I am just looking for pointers to where to find code that will allow me to replace a controller at runtime. We can safely assume it happens before the controller is used the first time.

 

Thank you . I appreciate any help.

 

Reply | Threaded
Open this post in threaded view
|

Re: Load controllers dynamically

bksaville
I don't remember the load order off the top of my head, but it *may* be possible to just override the bean name of a certain controller to have an alias (look as springConfig.addAlias in the bean builder), even in Bootstrap.  Keep in mind that controller bean names are the full class name and not the shortened name (com.example.MyController instead of myController).

-Brian


On Fri, Apr 5, 2013 at 12:50 PM, Sergei Rahouski <[hidden email]> wrote:

Hi all,

 

We need to add a way to dynamically change certain parts of the application based on customer. The customer number is determined on the startup and never changes during the application life time.

 

Based on the customer we would like to replace controllers with customized versions of controllers, replace views and services too.

 

I’ve played with Grails plugin architecture a bit and it looked promising but it would take weeks to get our application to play nice with it. Plus it is not entirely clear how to dynamically load plugins based on a setting.

 

Short term I would like to be able to program customization logic myself by creating a folder structure like this:

 

grails-app

    customers

       customer1

            controllers

            services

            src

            views

            resources.groovy

       customer2

          controllers

         services

         src

          views

          resources.groovy

 

I am pretty clear on how to load additional services at runtime and how to make them override existing. Controllers though are not as straightforward because Grails does a bunch of stuff to make them useful.

 

I am just looking for pointers to where to find code that will allow me to replace a controller at runtime. We can safely assume it happens before the controller is used the first time.

 

Thank you . I appreciate any help.

 


Reply | Threaded
Open this post in threaded view
|

Re: Load controllers dynamically

Dean Del Ponte-2
I"m not sure exactly what it is you're trying to accomplish.  Maybe I'd better understand if you would share a user story or two.

Is this a multi-tenant application where each tenant has customized functionality?

- Dean Del Ponte


On Fri, Apr 5, 2013 at 2:01 PM, Brian Saville <[hidden email]> wrote:
I don't remember the load order off the top of my head, but it *may* be possible to just override the bean name of a certain controller to have an alias (look as springConfig.addAlias in the bean builder), even in Bootstrap.  Keep in mind that controller bean names are the full class name and not the shortened name (com.example.MyController instead of myController).

-Brian


On Fri, Apr 5, 2013 at 12:50 PM, Sergei Rahouski <[hidden email]> wrote:

Hi all,

 

We need to add a way to dynamically change certain parts of the application based on customer. The customer number is determined on the startup and never changes during the application life time.

 

Based on the customer we would like to replace controllers with customized versions of controllers, replace views and services too.

 

I’ve played with Grails plugin architecture a bit and it looked promising but it would take weeks to get our application to play nice with it. Plus it is not entirely clear how to dynamically load plugins based on a setting.

 

Short term I would like to be able to program customization logic myself by creating a folder structure like this:

 

grails-app

    customers

       customer1

            controllers

            services

            src

            views

            resources.groovy

       customer2

          controllers

         services

         src

          views

          resources.groovy

 

I am pretty clear on how to load additional services at runtime and how to make them override existing. Controllers though are not as straightforward because Grails does a bunch of stuff to make them useful.

 

I am just looking for pointers to where to find code that will allow me to replace a controller at runtime. We can safely assume it happens before the controller is used the first time.

 

Thank you . I appreciate any help.

 



Reply | Threaded
Open this post in threaded view
|

RE: Load controllers dynamically

Sergei Rahouski

The application will have multiple customizations built-in in the compiled war file. The active customization will be selected at runtime. Only one client can use the system at the same time so it is not a multi-tenant application.

 

From: Dean Del Ponte [mailto:[hidden email]]
Sent: Friday, April 05, 2013 3:38 PM
To: [hidden email]
Subject: Re: [grails-user] Load controllers dynamically

 

I"m not sure exactly what it is you're trying to accomplish.  Maybe I'd better understand if you would share a user story or two.

 

Is this a multi-tenant application where each tenant has customized functionality?

 

- Dean Del Ponte

 

On Fri, Apr 5, 2013 at 2:01 PM, Brian Saville <[hidden email]> wrote:

I don't remember the load order off the top of my head, but it *may* be possible to just override the bean name of a certain controller to have an alias (look as springConfig.addAlias in the bean builder), even in Bootstrap.  Keep in mind that controller bean names are the full class name and not the shortened name (com.example.MyController instead of myController).

 

-Brian

 

On Fri, Apr 5, 2013 at 12:50 PM, Sergei Rahouski <[hidden email]> wrote:

Hi all,

 

We need to add a way to dynamically change certain parts of the application based on customer. The customer number is determined on the startup and never changes during the application life time.

 

Based on the customer we would like to replace controllers with customized versions of controllers, replace views and services too.

 

I’ve played with Grails plugin architecture a bit and it looked promising but it would take weeks to get our application to play nice with it. Plus it is not entirely clear how to dynamically load plugins based on a setting.

 

Short term I would like to be able to program customization logic myself by creating a folder structure like this:

 

grails-app

    customers

       customer1

            controllers

            services

            src

            views

            resources.groovy

       customer2

          controllers

         services

         src

          views

          resources.groovy

 

I am pretty clear on how to load additional services at runtime and how to make them override existing. Controllers though are not as straightforward because Grails does a bunch of stuff to make them useful.

 

I am just looking for pointers to where to find code that will allow me to replace a controller at runtime. We can safely assume it happens before the controller is used the first time.

 

Thank you . I appreciate any help.

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Load controllers dynamically

tomas lin
Take a look at Burt's Dynamic Controllers plugin - http://grails.org/plugin/dynamic-controller


I would also suggest investigating feature flipping, where you turn a set of features on and off based on a customer. 

On Fri, Apr 5, 2013 at 9:47 PM, Sergei Rahouski <[hidden email]> wrote:

The application will have multiple customizations built-in in the compiled war file. The active customization will be selected at runtime. Only one client can use the system at the same time so it is not a multi-tenant application.

 

From: Dean Del Ponte [mailto:[hidden email]]
Sent: Friday, April 05, 2013 3:38 PM
To: [hidden email]
Subject: Re: [grails-user] Load controllers dynamically

 

I"m not sure exactly what it is you're trying to accomplish.  Maybe I'd better understand if you would share a user story or two.

 

Is this a multi-tenant application where each tenant has customized functionality?

 

- Dean Del Ponte

 

On Fri, Apr 5, 2013 at 2:01 PM, Brian Saville <[hidden email]> wrote:

I don't remember the load order off the top of my head, but it *may* be possible to just override the bean name of a certain controller to have an alias (look as springConfig.addAlias in the bean builder), even in Bootstrap.  Keep in mind that controller bean names are the full class name and not the shortened name (com.example.MyController instead of myController).

 

-Brian

 

On Fri, Apr 5, 2013 at 12:50 PM, Sergei Rahouski <[hidden email]> wrote:

Hi all,

 

We need to add a way to dynamically change certain parts of the application based on customer. The customer number is determined on the startup and never changes during the application life time.

 

Based on the customer we would like to replace controllers with customized versions of controllers, replace views and services too.

 

I’ve played with Grails plugin architecture a bit and it looked promising but it would take weeks to get our application to play nice with it. Plus it is not entirely clear how to dynamically load plugins based on a setting.

 

Short term I would like to be able to program customization logic myself by creating a folder structure like this:

 

grails-app

    customers

       customer1

            controllers

            services

            src

            views

            resources.groovy

       customer2

          controllers

         services

         src

          views

          resources.groovy

 

I am pretty clear on how to load additional services at runtime and how to make them override existing. Controllers though are not as straightforward because Grails does a bunch of stuff to make them useful.

 

I am just looking for pointers to where to find code that will allow me to replace a controller at runtime. We can safely assume it happens before the controller is used the first time.

 

Thank you . I appreciate any help.