-
Notifications
You must be signed in to change notification settings - Fork 43
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
Feature Request: Support binding factory methods to different types with annotation #177
Comments
Use case makes sense. Discussion from here is whether is warrants a new API. Some questions around this API: It's confusing whether the |
The @Expose
@BindTo(Foo.class)
private abstract FooImpl fooImpl(); I think max clarity would probably provided by this, but not sure if you want to duplictate the expose semantics in addition to adding this new functionality: @BindTo(Foo.class, expose=true)
private abstract FooImpl fooImpl(); |
I do not agree with this proposal.
The drawback of a new api/annotation doesn't justify the small benefit of
the syntactic conciseness.
We already support aliases through the
abstract Foo foo(FooImpl fooImpl)
So duplicating the api for the same declaration is highly redundant.
For context we also debated this extension at the Facebook Ultralight DI
project and reached this conclusion.
Also in my view hiding the Impl from the graph can be also supported by a
warning at the IDE level and doesn't need to be a core part of the api.
…On Tue, Jan 21, 2020, 4:46 PM James Barr ***@***.***> wrote:
The @expose would only expose the type provided by the @bindto which
overrides the type from the factory. Would that maybe be clearer by using
private?
@***@***.***(Foo.class)private abstract FooImpl fooImpl();
I think max clarity would probably provided by this, but not sure if you
want to duplictate the expose semantics in addition to adding this new
functionality:
@bindto(Foo.class, expose=true)private abstract FooImpl fooImpl();
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#177?email_source=notifications&email_token=AADH7LOU2DA6EGWNA5SJPPLQ66JODA5CNFSM4KJ5UXG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJR2L5I#issuecomment-576955893>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADH7LOU4QVOOCIEDROAIPDQ66JODANCNFSM4KJ5UXGQ>
.
|
I noticed that in some scopes, I find myself needing to create many class implementations for types with lots of parameters, but I only want to expose their interface type for encapsulation.
Given interface
Foo
and concrete implementationFooImpl
with 5+ constructor parameters, instead of needing to write a Scope like:It'd be cleaner and less verbose when we have a lot of these in our scope to be able to use an annotation to override the type the newly created object is bound to:
This would use the primary constructor in FooImpl to instantiate a new instance, but only add it to the DI graph as if a new instance of
Foo
was created.The text was updated successfully, but these errors were encountered: