Search Results

Search found 94 results on 4 pages for 'guice'.

Page 2/4 | < Previous Page | 1 2 3 4  | Next Page >

  • Java : Inner class of an interface (from google guice)

    - by bsreekanth
    Hello, I was going through the source of google guice, and found an unfamiliar piece of code. It would be great learning if someone can clarify it. I have very basic understanding of inner classes, as they keep the implementation details close to the public interface. Otherwise the inner class may pollute the namespace. Now, I see the below lines at public static final Scope SINGLETON = new Scope() { public <T> Provider<T> scope(final Key<T> key, final Provider<T> creator) { return new Provider<T>() { ......... } It assign an inner class instance to the static variable, but Scope is an interface defined as (at) public interface Scope Is it possible to instantiate the interface?? or is it a succinct syntax for an anonymous implementation of an interface?? If anyone can explain what the author is intended by multiple nested classes above (Scope and Provider), and why it make sense to implement this way, it would help me to understand. thanks.

    Read the article

  • Binding a value to one of two possibilities in Guice

    - by Kelvin Chung
    Suppose I have a value for which I have a default, which can be overridden if System.getProperty("foo") is set. I have one module for which I have bindConstant().annotatedWith(Names.named("Default foo")).to(defaultValue); I'm wondering what the best way of implementing a module for which I want to bind something annotated with "foo" to System.getProperty("foo"), or, if it does not exist, the "Default foo" binding. I've thought of a simple module like so: public class SimpleIfBlockModule extends AbstractModule { @Override public void configure() { requireBinding(Key.get(String.class, Names.named("Default foo"))); if (System.getProperties().containsKey("foo")) { bindConstant().annotatedWith(Names.named("foo")).to(System.getProperty("foo")); } else { bind(String.class).annotatedWith(Names.named("foo")).to(Key.get(String.class, Names.named("Default foo"))); } } } I've also considered creating a "system property module" like so: public class SystemPropertyModule extends PrivateModule { @Override public void configure() { Names.bindProperties(binder(), System.getProperties()); if (System.getProperties().contains("foo")) { expose(String.class).annotatedWith(Names.named("foo")); } } } And using SystemPropertyModule to create an injector that a third module, which does the binding of "foo". Both of these seem to have their downsides, so I'm wondering if there is anything I should be doing differently. I was hoping for something that's both injector-free and reasonably generalizable to multiple "foo" attributes. Any ideas?

    Read the article

  • setter injection guice + wicket

    - by chris-gr
    Hi, I have a Wicket Web Page where I create a new Object of class A: A a = new A(User u); In A I would like to have setter injection, however this is actually not done. I have heard that one must provide an empty constructor but how is it possible to have also a non - empty constructor with setter injection?

    Read the article

  • JSR-299 CDI / Weld vs. Google Guice

    - by deamon
    Weld, the JSR-299 Contexts and Dependency Injection reference implementation, considers itself as a kind of successor of Spring and Guice. CDI was influenced by a number of existing Java frameworks, including Seam, Guice and Spring. However, CDI has its own, very distinct, character: more typesafe than Seam, more stateful and less XML-centric than Spring, more web and enterprise-application capable than Guice. But it couldn't have been any of these without inspiration from the frameworks mentioned and lots of collaboration and hard work by the JSR-299 Expert Group (EG). http://docs.jboss.org/weld/reference/latest/en-US/html/1.html What makes Weld more capable for enterprise application compared to Guice? Are there any advantages or disadvantages compared to Guice? What do you think about Guice AOP compared to Weld interceptors? What about performance?

    Read the article

  • How do I get google guice to inject a custom logger, say a commons-logging or log4j logger

    - by Miguel Silva
    Google guice has a built-in logger binding (http://code.google.com/p/google-guice/wiki/BuiltInBindings). But what if I want to use a commons-logging or log4j logger? Can I get guice to inject a Log created by LogFactory.getLog(CLASS.class) But having the same behavior as in built-in binding: The binding automatically sets the logger's name to the name of the class into which the Logger is being injected.. Does it even makes sense? Or shout I simply use the built-in java Logger? Or just use commons-logging without injections?

    Read the article

  • Guice creates Swing components outside of UI thread problem?

    - by Boris Pavlovic
    I'm working on Java Swing application with Google Guice as an IOC container. Things are working pretty well. There are some UI problems. When a standard L&F is replaced with Pushing pixels Substance L&F application is not running due to Guice's Swing components creation outside of UI thread. Is there a way to tell Guice to create Swing components in the UI thread? Maybe I should create custom providers which will return Swing components after SwingUtilities.invokeAndWait(Runnable) creates them. I don't like the idea of running the whole application in UI thread, but maybe it's just a perfect solution.

    Read the article

  • Should I use Spring or Guice for a Tomcat/Wicket/Hibernate project?

    - by Trevor Allred
    I'm building a new web application that uses Linux, Apache, Tomcat, Wicket, JPA/Hibernate, and MySQL. My primary need is Dependency Injection, which both Spring and Guice can do well. I think I need transaction support that would come with Spring and JTA but I'm not sure. The site will probably have about 20 pages and I'm not expect huge traffic. Should I use Spring or Guice? Feel free to ask and followup questions and I'll do my best to update this.

    Read the article

  • How do you create a non-Thread-based Guice custom Scope?

    - by Russ
    It seems that all Guice's out-of-the-box Scope implementations are inherently Thread-based (or ignore Threads entirely): Scopes.SINGLETON and Scopes.NO_SCOPE ignore Threads and are the edge cases: global scope and no scope. ServletScopes.REQUEST and ServletScopes.SESSION ultimately depend on retrieving scoped objects from a ThreadLocal<Context>. The retrieved Context holds a reference to the HttpServletRequest that holds a reference to the scoped objects stored as named attributes (where name is derived from com.google.inject.Key). Class SimpleScope from the custom scope Guice wiki also provides a per-Thread implementation using a ThreadLocal<Map<Key<?>, Object>> member variable. With that preamble, my question is this: how does one go about creating a non-Thread-based Scope? It seems that something that I can use to look up a Map<Key<?>, Object> is missing, as the only things passed in to Scope.scope() are a Key<T> and a Provider<T>. Thanks in advance for your time.

    Read the article

  • What is the best way to use Guice and JMock together?

    - by Yishai
    I have started using Guice to do some dependency injection on a project, primarily because I need to inject mocks (using JMock currently) a layer away from the unit test, which makes manual injection very awkward. My question is what is the best approach for introducing a mock? What I currently have is to make a new module in the unit test that satisfies the dependencies and bind them with a provider that looks like this: public class JMockProvider<T> implements Provider<T> { private T mock; public JMockProvider(T mock) { this.mock = mock; } public T get() { return mock; } } Passing the mock in the constructor, so a JMock setup might look like this: final CommunicationQueue queue = context.mock(CommunicationQueue.class); final TransactionRollBack trans = context.mock(TransactionRollBack.class); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(CommunicationQueue.class).toProvider(new JMockProvider<QuickBooksCommunicationQueue>(queue)); bind(TransactionRollBack.class).toProvider(new JMockProvider<TransactionRollBack>(trans)); } }); context.checking(new Expectations() {{ oneOf(queue).retrieve(with(any(int.class))); will(returnValue(null)); never(trans); }}); injector.getInstance(RunResponse.class).processResponseImpl(-1); Is there a better way? I know that AtUnit attempts to address this problem, although I'm missing how it auto-magically injects a mock that was created locally like the above, but I'm looking for either a compelling reason why AtUnit is the right answer here (other than its ability to change DI and mocking frameworks around without changing tests) or if there is a better solution to doing it by hand.

    Read the article

  • Isthere an equivalent in CDI(WELD) to Guice modules and Inject ?

    - by mP
    I like the way Guice makes it fairly straight forward to manually create your own modules each with their own bindings done in code. CDI on the other hand seems to rely more on magic rather than programmatic access to sest bindings. Am i wrong or how can one achieve the same effect with WELD. Any code sample would be appreciated...

    Read the article

  • Projects with browsable source using dependency injection w/ guice?

    - by André
    I often read about dependency injection and I did research on google and I understand in theory what it can do and how it works, but I'd like to see an actual code base using it (Java/guice would be preferred). Can anyone point me to an open source project, where I can see, how it's really used? I think browsing the code and seeing the whole setup shows me more than the ususal snippets in the introduction articles you find around the web. Thanks in advance!

    Read the article

  • How does the Built-in Bindings of Google Guice work?

    - by lony
    Hello, I tried Google Guice the first time and find it very nice. But, when I reached the part of Built-in Bindings I do not understand the examples. For me it looks like I can use it for logging like an interceptor, but I don't know how. Could someone of you explain this type of Binding and how I can use it? And maybe (if it's possible) use it for logging?

    Read the article

  • Using Grapher on GIN application with GinModuleAdapter

    - by Epaga
    I've been trying to use Grapher on my GIN project. But trying to create an Injector to give the InjectorGrapher has not been working. Right in the first line of my code: Injector injector = Guice.createInjector( new GinModuleAdapter( new MyGinModule() ) ); it crashes with Exception in thread "main" java.lang.AssertionError: should never be actually called at com.google.gwt.inject.rebind.adapter.GwtDotCreateProvider.get(GwtDotCreateProvider.java:43) at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48) at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811) at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at com.google.inject.Scopes$1$1.get(Scopes.java:54) at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48) at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42) at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66) at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84) at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111) at com.google.inject.BoundProviderFactory.get(BoundProviderFactory.java:56) at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811) at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at com.google.inject.Scopes$1$1.get(Scopes.java:54) at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48) at com.google.inject.InjectorBuilder$1.call(InjectorBuilder.java:200) at com.google.inject.InjectorBuilder$1.call(InjectorBuilder.java:194) at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:804) at com.google.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:194) at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:176) at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113) at com.google.inject.Guice.createInjector(Guice.java:92) at com.google.inject.Guice.createInjector(Guice.java:69) at com.google.inject.Guice.createInjector(Guice.java:59) at com.me.myself.Grapher.main(Grapher.java:20) What gives?

    Read the article

  • How do I subtract a binding using a Guice module override?

    - by Jimmy Yuen Ho Wong
    So according to my testing, If you have something like: Module modA = new AbstractModule() { public void configure() { bind(A.class).to(AImpl.class); bind(C.class).to(ACImpl.class); bind(E.class).to(EImpl.class); } } Module modB = New AbstractModule() { public void configure() { bind(A.class).to(C.class); bind(D.class).to(DImpl.class); } } Guice.createInjector(Modules.overrides(modA, modB)); // gives me binding for A, C, E AND D with A overridden to A->C. But what if you want to remove the binding for E in modB? I can't seem to find a way to do this without having to break the bind for E into a separate module. Is there a way?

    Read the article

  • How do I write a Guice Provider that doesn't explicitly create objects?

    - by ripper234
    Say I have a ClassWithManyDependencies. I want to write a Guice Provider for this class, in order to create a fresh instance of the class several times in my program (another class will depend on this Provider and use it at several points to create new instances). One way to achieve this is by having the Provider depend on all the dependencies of ClassWithManyDependencies. This is quite ugly. Is there a better way to achieve this? Note - I certainly don't want the Provider to depend on the injector. Another option I considered is having ClassWithManyDependencies and ClassWithManyDependenciesProvider extend the same base class, but it's butt ugly.

    Read the article

  • Where should I put bindings for dependency injection?

    - by Mike G
    I'm new to dependency injection and though I've really liked it so far, I'm not sure where bindings should go. I'm using Guice in Java, so some of what I say might be specific to just Guice. As I see it, there's two options: Accompanying the class(s) its needed for. Then, just write install(OtherClassModule.class) in whatever other modules want to be able to use said class. As I see it, the advantage of this is that classes that want to use it (or manage classes that want to use it) don't need to know any of the implementation detail. The issue I see is that what if two classes want to use two different versions of the same class? There's a lot of customization possible because of DI and this seems to restrict it a lot. Implemented in the module of the class(s) its needed for. It's the flip of what I said above. Now you have customization, but not encapsulation. Is there a third option? Am I misunderstanding something obvious? What's the best practice?

    Read the article

  • What is the correct stage to use for Google Guice in production in an application server?

    - by Yishai
    It seems like a strange question (the obvious answer would Production, duh), but if you read the java docs: /** * We want fast startup times at the expense of runtime performance and some up front error * checking. */ DEVELOPMENT, /** * We want to catch errors as early as possible and take performance hits up front. */ PRODUCTION Assuming a scenario where you have a stateless call to an application server, the initial receiving method (or there abouts) creates the injector new every call. If there all of the module bindings are not needed in a given call, then it would seem to have been better to use the Development stage (which is the default) and not take the performance hit upfront, because you may never take it at all, and here the distinction between "upfront" and "runtime performance" is kind of moot, as it is one call. Of course the downside of this would appear to be that you would lose the error checking, causing potential code paths to cause a problem by surprise. So the question boils down to are the assumptions in the above correct? Will you save performance on a large set of modules when the given lifetime of an injector is one call?

    Read the article

  • Properties framework in java apps

    - by Roman
    Hi All I have been using spring for a while as my IOC. It has also a very nice way of injecting properties in your beans. Now I am participating in a new project where the IOC is Guice. I dont understand fully the concept how should I inject properties in to my beans using Guice. The question : Is it actually possible to inject raw properties ( strings , ints ) into my guice beans. If the answer is no , than maybe you know some nice Properties Framework for java. Because right now I wanted to use the ResourceBundle class for simple properties management in my app. But after using spring for a while this just dont seem seriously enought for me.

    Read the article

  • What are the downsides to using dependency injection?

    - by kerry
    I recently came across an interesting question on stack overflow with some interesting reponses.  I like this post for three reasons. First, I am a big fan of dependency injection, it forces you to decouple your code, create cohesive interfaces, and should result in testable classes. Second, the author took the approach I usually do when trying to evaluate a technique or technology; suspend personal feelings and try to find some compelling arguments against it. Third, it proved that it is very difficult to come up with a compelling argument against dependency injection. What are the downsides to using dependency injection?

    Read the article

  • How do I apply a servlet filter when serving an HTML page directly?

    - by Philippe Beaudoin
    First off, I'm using Google AppEngine and Guice, but I suspect my problem is not related to these. When the user connect to my (GWT) webapp, the URL is a direct html page. For example, in development mode, it is: http://127.0.0.1:8888/Puzzlebazar.html?gwt.codesvr=127.0.0.1:9997. Now, I setup my web.xml in the following way: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>PuzzleBazar</display-name> <!-- Default page to serve --> <welcome-file-list> <welcome-file>Puzzlebazar.html</welcome-file> </welcome-file-list> <filter> <filter-name>guiceFilter</filter-name> <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> </filter> <filter-mapping> <filter-name>guiceFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- This Guice listener hijacks all further filters and servlets. Extra filters and servlets have to be configured in your ServletModule#configureServlets() by calling serve(String).with(Class<? extends HttpServlet>) and filter(String).through(Class<? extends Filter) --> <listener> <listener-class>com.puzzlebazar.server.guice.MyGuiceServletContextListener </listener-class> </listener> </web-app> Since I'm using Guice, I have to configure extra filters in my ServletModule, where I do this: filter("*.html").through( SecurityCookieFilter.class ); But my SecurityCookieFilter.doFilter is never called. I tried things like "*.html*" or <url-pattern>*</url-pattern> but to no avail. Any idea how I should do this?

    Read the article

  • GWT Acegi alternative

    - by DroidIn.net
    I'm starting new project. The client interface is based on GWT (and GXT) I have no say it's predetermined. However I can pick and choose as far as server side so I can have some fun and hopefully learn something new in the process. Some requirements are : Exchange with server will be through use of JSON, most if not all of UI will be generated by GWT (JS) on the client, so the client/serve exchange will be limited to data exchange as much as possible No Hibernate (it's not really supported on the proprietary db I will be connecting to). In the past projects people would use JDBC or iBATIS Some sort of IoC (I'm thinking Guice just to stick with Google) Some sort of Security framework based on LDAP. In the past we would use Spring security (Acegi) but it wasn't ideal and we had to customize it a lot So basically should I stick with tried-and-true Spring/Acegi or try something based on Guice? And what that "something" would be and how mature is it?

    Read the article

  • Android - Looking for an AOP solution

    - by Serj Lotutovici
    I'm writing an application that on the bottom line uses it's internal API for some manipulations. The problem is that to call any method provided by that class first I (or anybody who uses the API) have to call #prepare() and after that #cleanup(). It all worked fine until the application and the API started to grow. And the risk of not calling one of the supplied methods before or after the API is now to big to be ignored (which makes it a bug risky application). Searching for a solution I found this question. I use Google Guice in my app for other purposes, but Android doesn't support AOP, that's why a use only guice-no_aop-x.jar. So I end-up with two questions: Is there an AOP solution for android to implement the same approach that is shown in the link above? Or may be someone has an idea that will be suitable for my case? Thanks in advice!

    Read the article

< Previous Page | 1 2 3 4  | Next Page >