[fpc-devel] Inversion of control for TCustomHTTPModule and descendants
Michael Van Canneyt
michael at freepascal.org
Tue Mar 6 20:09:12 CET 2012
On Tue, 6 Mar 2012, Sven Barth wrote:
> Am 06.03.2012 17:35, schrieb michael.vancanneyt at wisa.be:
>> 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.
>>> 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
>> 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.
- Global OnInitModule
- Module-Specific AfterInitModule
More information about the fpc-devel