You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Umesh Awasthi <um...@gmail.com> on 2012/11/30 20:21:25 UTC

Preferred Way to Inject Dependency in plugin

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


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

Re: Preferred Way to Inject Dependency in plugin

Posted by Umesh Awasthi <um...@gmail.com>.
Seems like there is no direct way to accomplish this and i need to look out
some other alternate way to do this :(


On Tue, Dec 4, 2012 at 7:42 AM, Umesh Awasthi <um...@gmail.com>wrote:

> 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 <lu...@apache.org>wrote:
>
>> 2012/11/30 Umesh Awasthi <um...@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/
>
>
>



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

Re: Preferred Way to Inject Dependency in plugin

Posted by Lukasz Lenart <lu...@apache.org>.
2012/12/5 Umesh Awasthi <um...@gmail.com>:
> I believe with Struts 3.x we should have such mechanism where we can use
> Internal DI to inject dependency in such way :)

But you can achieve the same with Maven right now, just specify an
optional dependency. Beside Validation class can load default provider
http://docs.jboss.org/hibernate/beanvalidation/spec/1.1/api/javax/validation/Validation.html


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


Re: Preferred Way to Inject Dependency in plugin

Posted by Umesh Awasthi <um...@gmail.com>.
Thanks Lukasz!!!

I believe with Struts 3.x we should have such mechanism where we can use
Internal DI to inject dependency in such way :)

On Wed, Dec 5, 2012 at 12:45 PM, Lukasz Lenart <lu...@apache.org>wrote:

> 2012/12/4 Umesh Awasthi <um...@gmail.com>:
> > 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
>
> I thought there should be a common way to load ValidationProvider,
> like you just check Class.forName("javax....ValidationProvider") and
> then throws exception that the user must add missing dependency. In
> Maven you can define given implementation as an optional and user will
> have to define a concrete implementation when he will try to use the
> plugin.
>
>
> 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/

Re: Preferred Way to Inject Dependency in plugin

Posted by Lukasz Lenart <lu...@apache.org>.
2012/12/4 Umesh Awasthi <um...@gmail.com>:
> 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

I thought there should be a common way to load ValidationProvider,
like you just check Class.forName("javax....ValidationProvider") and
then throws exception that the user must add missing dependency. In
Maven you can define given implementation as an optional and user will
have to define a concrete implementation when he will try to use the
plugin.


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


Re: Preferred Way to Inject Dependency in plugin

Posted by Umesh Awasthi <um...@gmail.com>.
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 <lu...@apache.org>wrote:

> 2012/11/30 Umesh Awasthi <um...@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/

Re: Preferred Way to Inject Dependency in plugin

Posted by Lukasz Lenart <lu...@apache.org>.
2012/11/30 Umesh Awasthi <um...@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


Fwd: Preferred Way to Inject Dependency in plugin

Posted by Umesh Awasthi <um...@gmail.com>.
Any inputs on below mentioned problem?

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




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