Announcing Sangria

77 views
Skip to first unread message

Tavian Barnes

unread,
Apr 2, 2014, 3:18:01 PM4/2/14
to google...@googlegroups.com
Sangria is a project where I'll be releasing some Guice extensions that I've written.  Currently it provides context-sensitive injection, and through that, first-class (constructor) injection of non-JUL loggers like SLF4J.

The API for context-sensitive injection looks like this:

public interface ContextSensitiveProvider<T> {
    T getInContext(InjectionPoint injectionPoint);
    T getInUnknownContext();
}

public class YourModule extends AbstractModule {
    @Override
    protected void configure() {
        ContextSensitiveBinder.create(binder())
                .bind(YourType.class)
                .toContextSensitiveProvider(YourProvider.class);
    }
}

The implementation is based on Noctarius's suggestion from an old thread here to use a ProvisionListener together with a ThreadLocal.

I wrote a blog post about it here.  The code is released under the WTFPL, and is available on GitHub.  Feel free to comment or send pull requests.

Christian Gruber

unread,
Apr 2, 2014, 3:52:31 PM4/2/14
to google...@googlegroups.com
This is pretty Badass.

One question - could you consider also licensing it under Apache 2.0 or
something else the OSI has approved as an open-source license? WTFPL
basically means we could never use it in Google, nor could Googlers
contribute back to it, owing to its lack of warranty disclaimer and very
vague rights grant.

That said, this is a pretty cool extension. Need to look into the
performance implications of context sensitive provision, but I like it,
conceptually.

c.

On 2 Apr 2014, at 12:18, Tavian Barnes wrote:

> Sangria <http://tavianator.com/sangria/> is a project where I'll be
> releasing some Guice extensions that I've written. Currently it
> provides
> context-sensitive injection, and through that, first-class
> (constructor)
> injection of non-JUL loggers like SLF4J.
>
> The API for context-sensitive injection looks like this:
>
> *public* *interface* ContextSensitiveProvider<T> {
> T getInContext(InjectionPoint injectionPoint);
> T getInUnknownContext();
> }
>
> public class YourModule extends AbstractModule {
> @Override
> protected void configure() {
> ContextSensitiveBinder.create(binder())
> .bind(YourType.class)
> .toContextSensitiveProvider(YourProvider.class);
> }
> }
>
> The implementation is based on Noctarius's suggestion from an old
> thread
> here to use a ProvisionListener together with a ThreadLocal.
>
> I wrote a blog post about it
> here<http://tavianator.com/2014/04/announcing-sangria/>.
> The code is released under the WTFPL <http://www.wtfpl.net/>, and is
> available on GitHub <https://github.com/tavianator/sangria>. Feel
> free to
> comment or send pull requests.
>
> --
> You received this message because you are subscribed to the Google
> Groups "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to google-guice...@googlegroups.com.
> To post to this group, send email to google...@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-guice.
> For more options, visit https://groups.google.com/d/optout.


Christian Gruber :: Google, Inc. :: Java Core Libraries :: Dependency
Injection
email: cgr...@google.com :::: mobile: +1 (646) 807-9839

David Hoffer

unread,
Apr 2, 2014, 4:08:51 PM4/2/14
to google...@googlegroups.com
I had the same thoughts on the license, Apache or something similar would be great.

-Dave


To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscribe@googlegroups.com.

To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.


Christian Gruber :: Google, Inc. :: Java Core Libraries :: Dependency Injection
email: cgr...@google.com :::: mobile: +1 (646) 807-9839
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscribe@googlegroups.com.

Tavian Barnes

unread,
Apr 2, 2014, 4:30:14 PM4/2/14
to google...@googlegroups.com
On Wednesday, 2 April 2014 15:52:31 UTC-4, Christian Gruber wrote:
This is pretty Badass.

Thanks! 
 
One question - could you consider also licensing it under Apache 2.0 or
something else the OSI has approved as an open-source license?  WTFPL
basically means we could never use it in Google, nor could Googlers
contribute back to it, owing to its lack of warranty disclaimer and very
vague rights grant.

I'm surprised that you wouldn't be able to use it internally (it's basically public domain), but good point about your own contributions.  I'll re-license to Apache to keep things simple.
 
That said, this is a pretty cool extension.  Need to look into the
performance implications of context sensitive provision, but I like it,
conceptually.
 
I haven't benchmarked it but it shouldn't be too horrible.  Obviously something based on InternalFactory would be faster.

Tavian Barnes

unread,
Apr 2, 2014, 4:48:06 PM4/2/14
to google...@googlegroups.com
I re-licensed it under the Apache License Version 2.0 (same as Guice itself).
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.

To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.


Christian Gruber :: Google, Inc. :: Java Core Libraries :: Dependency Injection
email: cgr...@google.com :::: mobile: +1 (646) 807-9839


--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.

Christian Gruber

unread,
Apr 2, 2014, 5:13:16 PM4/2/14
to google...@googlegroups.com
On 2 Apr 2014, at 13:30, Tavian Barnes wrote:

>> One question - could you consider also licensing it under Apache 2.0
>> or
>> something else the OSI has approved as an open-source license? WTFPL
>> basically means we could never use it in Google, nor could Googlers
>> contribute back to it, owing to its lack of warranty disclaimer and
>> very
>> vague rights grant.
>>
>
> I'm surprised that you wouldn't be able to use it internally (it's
> basically public domain), but good point about your own contributions.
> I'll re-license to Apache to keep things simple.

It comes down to this (remembering that IANAL). WTFPL and other
near-public-domain licenses simply are too vague and weak to be secure
bases to defend against a later intellectual property claim. It's like
saying "yeah, use it, whatever" and then the vagueness leaves open
future lawsuits of "well, I didn't mean they could use it in this
specific context." So it becomes an Admiral-Akbar-style trap, legally
speaking, and companies are at-risk if they then use the code. Which is
why the OSI rejected it as an open-source license.

<shrug>

Thanks for being open to alternatives, though. Mighty awesome of you.

Christian.
Reply all
Reply to author
Forward
0 new messages