/*
 * Copyright (C) 2009-2016 Lightbend Inc. <https://www.lightbend.com>
 */
package play.data.validation;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.validation.Validator;
import javax.validation.Validation;
import javax.validation.ConstraintValidatorFactory;

@Singleton
public class ValidatorProvider implements Provider<Validator> {

    private ConstraintValidatorFactory constraintValidatorFactory;

    @Inject
    public ValidatorProvider(ConstraintValidatorFactory constraintValidatorFactory) {
        this.constraintValidatorFactory = constraintValidatorFactory;
    }

    public Validator get() {
        return Validation.buildDefaultValidatorFactory().usingContext()
            .constraintValidatorFactory(constraintValidatorFactory)
            .getValidator();
    }

}
@@ -101,16 +101,64 @@
 ation;%0A%0A
+import java.util.concurrent.CompletableFuture;%0A%0A
 import j
@@ -360,16 +360,100 @@
 Factory;
+%0Aimport javax.validation.ValidatorFactory;%0A%0Aimport play.inject.ApplicationLifecycle;
 %0A%0A@Singl
@@ -534,26 +534,16 @@
 private 
-Constraint
 Validato
@@ -547,35 +547,25 @@
 atorFactory 
-constraintV
+v
 alidatorFact
@@ -668,24 +668,141 @@
 tory
-) %7B%0A        this
+, final ApplicationLifecycle lifecycle) %7B%0A        this.validatorFactory = Validation.byDefaultProvider().configure()%0A                
 .con
@@ -824,19 +824,17 @@
 rFactory
- = 
+(
 constrai
@@ -855,43 +855,88 @@
 tory
-;
+)
 %0A    
-%7D%0A%0A    public Validator get()
+            .buildValidatorFactory();%0A%0A        lifecycle.addStopHook(() -%3E
  %7B%0A 
@@ -946,123 +946,172 @@
     
+ 
-return Validation.buildDefaultValidatorFactory().usingContext()%0A            .constraintValidatorFactory(constraintV
+   this.validatorFactory.close();%0A            return CompletableFuture.completedFuture(null);%0A        %7D);%0A    %7D%0A%0A    public Validator get() %7B%0A        return this.v
 alid
@@ -1121,30 +1121,16 @@
 rFactory
-)%0A            
 .getVali

Create ValidatorFactory just once (#6800)