@SuppressWarnings("unchecked")
    private <T> T createInstance(Class<? extends T> implementation) {
        Constructor<?> constructor = null;
        for (Constructor<?> c : implementation.getConstructors()) {
            if (c.isAnnotationPresent(Inject.class)) {
                constructor = c;
                break;
            }
        }

        // fallback to default constructor
        if (constructor == null) {
            try {
                constructor = implementation.getConstructor();
            } catch (SecurityException | NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
        }

        if (constructor != null) {
            Object[] args = new Object[constructor.getParameterTypes().length];
            for (int i = 0; i < constructor.getParameterTypes().length; i++) {
                Named named = getNamedAnnotation(constructor.getParameterAnnotations()[i]);
                if (named != null) {
                    args[i] = get(constructor.getParameterTypes()[i], named.value());
                } else {
                    args[i] = get(constructor.getParameterTypes()[i]);
                }
            }
            try {
                return (T) constructor.newInstance(args);
                // TODO : populate fields as well?!?
            } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }

        } else {
            throw new IllegalArgumentException("Got no annotated constructor for " + implementation.getName());
        }

    }
{@code AbstractModule} provides a base class for annotation based dependency injection

@author tiwe
querydsl-codegen/src/main/java/com/querydsl/codegen/AbstractModule.java