xp-forge / inject

Dependency injection for the XP Framework
0 stars 0 forks source link

Add support for arrays and maps as constructor arguments #19

Closed thekid closed 6 years ago

thekid commented 6 years ago

The following is the equivalent of binding new SessionServer('sessions.server.lan', ['172.17.']):

web.session.Sessions=com.example.SessionServer("sessions.server.lan", ["172.17."])
                                                                      ^^^^^^^^^^^
                                                                      Arrays supported:)

This makes code like this obsolete:

string[sessions.allowed]=172.17.
string[sessions.balancer]=sessions.server.lan
$balancer= $inject->get('string', 'sessions.balancer');
$allowed= explode(',', $inject->get('string', 'sessions.allowed'));
$inject->bind(Sessions::class, new SessionServer($balancer, $allowed));
mikey179 commented 6 years ago

I'm a bit skeptical about eval() - what error message will a user of the library see in case of a syntax error? Will it be helpful in finding out what needs to be fixed?

thekid commented 6 years ago

@mikey179 I've been brainstorming about improvements to the config file format in #20. Maybe type=class and type=instance bindings should be done in code, and the config files focus only on named strings...