[fpc-devel] Inversion of control for TCustomHTTPModule and descendants
pascaldragon at googlemail.com
Thu Mar 8 11:47:00 CET 2012
Am 06.03.2012 20:09, schrieb Michael Van Canneyt:
> 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.
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 ;)
>>>> 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
> - Create
> - Global OnInitModule
> - Module-Specific AfterInitModule
> - HandleRequest
Reported with patch as http://bugs.freepascal.org/view.php?id=21441
More information about the fpc-devel