bind( MyClass.class ) is 100% optional.

I do it, but them I'm pedantic about things.

-d

On Nov 7, 3:49 pm, Moandji Ezana <[email protected]> wrote:
> On Sun, Nov 8, 2009 at 12:01 AM, dg <[email protected]> wrote:
>
> > just
>
> > bind(MyClass.class);
>
> Do you even have to do that? I thought JIT bindings were created when none
> existed, as long as you have a no-arg constructor or inject classes that are
> either bound or also have a no-arg constructor.
>
> Here are two JUnit test I wrote to try this out:
>
>     @Test
>     public void inject_no_arg_constructor_without_binding() {
>         Injector injector = Guice.createInjector();
>         TestEntity instance = injector.getInstance(TestEntity.class);
>         assertNotNull(instance);
>     }
>
>     @Test
>     public void
> inject_one_arg_constructor_that_takes_TestEntity_without_binding() {
>         Injector injector = Guice.createInjector();
>         InjectedEntity injectedEntity =
> injector.getInstance(InjectedEntity.class);
>         assertNotNull(injectedEntity);
>         assertNotNull(injectedEntity.testEntity);
>     }
>
> From the newly-updated wiki page: "
>
> While it is not recommended practice, sometimes you might need to bind a
> concrete class without having an interface to which to bind it."
>
> Like Jon Vaughan, I'm also fairly new to Guice. Why is this considered bad
> practice, if the interface would not raise the level of abstraction?
>
> And is there a difference between bind(MyClass.class) and not binding at
> all?
>
> Moandji
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to