-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working with Modules (as namespaces) #2
Comments
I found this bug a while back and am working on a patch already I just haven't had time to finish. Let me see if I can get a PR up. |
Thanks @elliotize, can confirm that this does work for my one-namespace-deep use-case, also works fine for Classes I'd like to have behave as macro define_singleton_di_providers(*klasses)
{% for klass in klasses %}
module {{ klass.id.split("::").reject { |k| k == klass.id.split("::").last}.join("::").id }}
class {{ klass }}Provider
Syringe.provide({{ klass }})
@@instance = {{ klass }}.new
def self.getInstance
@@instance
end
end
end
\{% if !{{klass}}.methods.select { |m| m.name == "initialize" }[0].args.empty? %}
Syringe.wrap({{ klass }})
\{% end %}
{% end %}
end ..this too could probably be improved. |
Sorry for the radio silence, was on a vacation. |
@stergiom I am working on my Spectrum Shard which is an async/domain event system using Syringe and realized I too have use for a singleton. Are you planning on making a PR to this repo or do you have another Shard you are adding it to. |
To be frank, I've only just started fiddling with Crystal and had not considered it. I've dropped a quick'n dirty off at #5, really just convenience macros for using as light IoC containers, but unsure about the scope/direction of Syringe to say whether this would be useful to add; Syringe.define_singleton_providers(
UseCase::DoAThing,
UseCase::DoSomeOtherThing
)
If it's just singelton behaviour that you're after, |
For singletons I'd expect a provider which returns an instance to indeed work. Onto the issue itself, good find, I've left a comment on the PR of elliotize, and I'm thinking how we can keep this code a bit more manageable. It looks like the pr of @elliotize works for N deep, so if we can figure out readability i'll merge. |
Environment
Issue
Where it works has expected here;
I'm having some trouble getting it to work with Modules;
..and trouble getting it to work from within Modules;
I've had limited success in using
Providers
here —which works for a single namespace, but not for dependencies across namespaces. Probably something I've missed, is there a canonical way in using this lib with namespaces?The text was updated successfully, but these errors were encountered: