Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-03

Inversion of control for TCustomHTTPModule and descendants

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth

Hello together!

I'm currently playing around with fcl-web a bit.

As I'd like to utilize inversion of control (e.g. passing things like database connections through the constructor [as one possible implementation of this pattern]) for my modules I'd like to ask whether it would be an idea for a feature request (maybe even with patch) to add an "OnCreateModule" event to TWebHandler which is called inside TWebHandler.HandleRequest before the module is created using CreateNew or Create?

Regards,
Sven

Reply by email

Unknown author
to Sven Barth
Sven Barth wrote 7 lines
Hello together! I'm currently playing around with fcl-web a bit. As I'd like to utilize inversion of control (e.g. passing things like database connections through the constructor [as one possible implementation of this pattern]) for my modules I'd like to ask whether it would be an idea

whooohoo - expensive terminology detected !!
"Inversion of Control"
:-)

for a feature request (maybe even with patch) to add an "OnCreateModule" event to TWebHandler which is called inside TWebHandler.HandleRequest before the module is created using CreateNew or Create?

Well, it can only be after create.
You need the instance first, and it is constructed with Create(New).

If you need to do something before that, there already is the OnGetModule handler.

But yes, a centralized initialization handler for webmodules is OK. Something like 'OnInitModule' or so ?

Michael.

Reply by email

Sven Barth
to Unknown author

Am 06.03.2012 17:35, schrieb

Show quoted text 15 lines
On Tue, 6 Mar 2012, Sven Barth wrote: > Hello together! > > I'm currently playing around with fcl-web a bit. > > As I'd like to utilize inversion of control (e.g. passing things like > database connections through the constructor [as one possible > implementation of this pattern]) for my modules I'd like to ask > whether it would be an idea whooohoo - expensive terminology detected !! "Inversion of Control" :-)

Sorry, but I don't get what you want to tell with that statement... :( (maybe my brain is all smashed today after I've read the documentation of a Delphi ORM ^^)

Show quoted text 7 lines
> for a feature request (maybe even with patch) to add an > "OnCreateModule" event to TWebHandler which is called inside > TWebHandler.HandleRequest before the module is created using CreateNew > or Create? Well, it can only be after create. You need the instance first, and it is constructed with Create(New).

That's the point: add an event which creates the module with custom parameters (because the module then can use a custom constructor). But see below.

If you need to do something before that, there already is the OnGetModule handler.

But OnGetModule only returns the class, not an instance...

But yes, a centralized initialization handler for webmodules is OK. Something like 'OnInitModule' or so ?

That's also an idea. At least then the creation of the module is kept inside TWebHandler (to use another expression: "open for extension, but closed for modification" ;) )

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 20 lines
Am 06.03.2012 17:35, schrieb > > > On Tue, 6 Mar 2012, Sven Barth wrote: > >> Hello together! >> >> I'm currently playing around with fcl-web a bit. >> >> As I'd like to utilize inversion of control (e.g. passing things like >> database connections through the constructor [as one possible >> implementation of this pattern]) for my modules I'd like to ask >> whether it would be an idea > > whooohoo - expensive terminology detected !! > "Inversion of Control" :-) Sorry, but I don't get what you want to tell with that statement... :( (maybe my brain is all smashed today after I've read the documentation of a Delphi ORM ^^)

I think "Inversion of Control" is a rather expensive word for what is in fact a simple configurable factory pattern. All examples I've seen of this were no more than that. But then, IT always has been very hype prone.

Show quoted text 24 lines
>> for a feature request (maybe even with patch) to add an >> "OnCreateModule" event to TWebHandler which is called inside >> TWebHandler.HandleRequest before the module is created using CreateNew >> or Create? > > Well, it can only be after create. You need the instance first, and it > is constructed with Create(New). That's the point: add an event which creates the module with custom parameters (because the module then can use a custom constructor). But see below. > If you need to do something before that, there already is the > OnGetModule handler. But OnGetModule only returns the class, not an instance... > But yes, a centralized initialization handler for webmodules is OK. > Something like 'OnInitModule' or so ? That's also an idea. At least then the creation of the module is kept inside TWebHandler (to use another expression: "open for extension, but closed for modification" ;) )

I think it would be better to use onInitModule. In fact, I would then also make a AfterInitModule event in TWebModule, which is called in any case, but definitely after the global handler and which gets passed the TRequest.

So
- Create
- Global OnInitModule
- Module-Specific AfterInitModule
- HandleRequest

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
Michael Van Canneyt wrote 28 lines
On Tue, 6 Mar 2012, Sven Barth wrote: > Am 06.03.2012 17:35, schrieb >> >> >> On Tue, 6 Mar 2012, Sven Barth wrote: >> >>> Hello together! >>> >>> I'm currently playing around with fcl-web a bit. >>> >>> As I'd like to utilize inversion of control (e.g. passing things like >>> database connections through the constructor [as one possible >>> implementation of this pattern]) for my modules I'd like to ask >>> whether it would be an idea >> >> whooohoo - expensive terminology detected !! >> "Inversion of Control" :-) > > Sorry, but I don't get what you want to tell with that statement... :( > (maybe my brain is all smashed today after I've read the documentation > of a Delphi ORM ^^) I think "Inversion of Control" is a rather expensive word for what is in fact a simple configurable factory pattern. All examples I've seen of this were no more than that. But then, IT always has been very hype prone.

Thanks for your explanation :)

Maybe "Inversion of Control" should not be seen as a pattern, but more as a concept that might utilize patterns (like the factory pattern). And it also helps to have a name for something: Just saying "we use inversion of control" is easier than saying "we have constructors where we pass in instances of classes our class relies on" or "we have some properties that need to be set before the class can be used". Of course this relies on the fact that the other person knows what "Inversion of Control" is about ;)

Show quoted text 35 lines
> >>> for a feature request (maybe even with patch) to add an >>> "OnCreateModule" event to TWebHandler which is called inside >>> TWebHandler.HandleRequest before the module is created using CreateNew >>> or Create? >> >> Well, it can only be after create. You need the instance first, and it >> is constructed with Create(New). > > That's the point: add an event which creates the module with custom > parameters (because the module then can use a custom constructor). But > see below. > >> If you need to do something before that, there already is the >> OnGetModule handler. > > But OnGetModule only returns the class, not an instance... > >> But yes, a centralized initialization handler for webmodules is OK. >> Something like 'OnInitModule' or so ? > > That's also an idea. At least then the creation of the module is kept > inside TWebHandler (to use another expression: "open for extension, > but closed for modification" ;) ) I think it would be better to use onInitModule. In fact, I would then also make a AfterInitModule event in TWebModule, which is called in any case, but definitely after the global handler and which gets passed the TRequest. So - Create - Global OnInitModule - Module-Specific AfterInitModule - HandleRequest

Reported with patch as http://bugs.freepascal.org/view.php?id=21441

Regards,
Sven

Reply by email