struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Umesh Awasthi <umeshawas...@gmail.com>
Subject Re: Preferred Way to Inject Dependency in plugin
Date Tue, 04 Dec 2012 02:12:52 GMT
Thanks for the inputs
I have this BeanValidationManagerProvider interface with a method  public
Validator getValidator() which will return Validator based on the actual
provider.

Any Bean Validator in reference to JSR303 will implement
javax.validation.Validator

So in my BeanValidationManagerProvider Impl class i was thinking to
providing a way to let  user inject actual provider with this setter method
 protected Class providerClass;
 public void setProviderClass( Class<? extends ValidationProvider>
providerClass)
    {
        this.providerClass = providerClass;
    }

and than i will be able to get Validator by a simple call
Validation.byProvider(this.providerClass).configure().buildValidatorFactory();

May be i am wrong in my process, but i was wondering how best we can let
user decide which provider they want to inject

Thanks
Umesh

On Tue, Dec 4, 2012 at 1:35 AM, Lukasz Lenart <lukaszlenart@apache.org>wrote:

> 2012/11/30 Umesh Awasthi <umeshawasthi@gmail.com>:
> > Hi All,
> >
> > I am creating a plugin to enable JSR303 validation, idea is to provide a
> > generic interface and let user provide which bean Validator they want to
> > use be it Hibernate Bean Validator or Apache one or any other which
> follow
> > specifications.
> >
> > I was thinking about what can be best way to inject that provider in my
> > plugin.
> >
> > I checked how Spring's  LocalValidatorFactoryBean
> > <
> http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-context/3.0.0.RELEASE/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java
> >Class
> > doing this, they have a default implementation but provide a way to let
> use
> > inject there own bean validation provider
> >
> > private Class providerClass;
> >
> > public void setProviderClass(Class<? extends ValidationProvider>
> > providerClass) {
> >
> > this.providerClass = providerClass;
> >
> > }
> >
> > What can be possible and best way to achieve this?
> > I do not want to use any other external API to add extra dependency
>
> You may create a custom interface (BeanValidationManagerProvider) with
> default implementation base on Apache, this way your plugin will be
> useable out of the box. User will always have an option to implement
> their own class and provide desired dependency.
>
>
> Regards
> --
> Ɓukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>


-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message