@@ -585,7 +585,7 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
585585 /** stop callback . */
586586 private List <CheckedConsumer <Registry >> onStop = new ArrayList <>();
587587
588- /** Mappers .*/
588+ /** Mappers . */
589589 @ SuppressWarnings ("rawtypes" )
590590 private Mapper mapper ;
591591
@@ -3039,9 +3039,9 @@ public Route.Definition assets(final String path, final String location) {
30393039 AssetHandler handler = new AssetHandler (location );
30403040 on ("*" , conf -> {
30413041 handler
3042- .cdn (conf .getString ("assets.cdn" ))
3043- .lastModified (conf .getBoolean ("assets.lastModified" ))
3044- .etag (conf .getBoolean ("assets.etag" ));
3042+ .cdn (conf .getString ("assets.cdn" ))
3043+ .lastModified (conf .getBoolean ("assets.lastModified" ))
3044+ .etag (conf .getBoolean ("assets.etag" ));
30453045 });
30463046 return assets (path , handler );
30473047 }
@@ -3458,6 +3458,130 @@ public Jooby mapper(final Mapper mapper) {
34583458 return this ;
34593459 }
34603460
3461+ /**
3462+ * Bind the provided abstract type to the given implementation:
3463+ *
3464+ * <pre>
3465+ * {
3466+ * bind(MyInterface.class, MyImplementation.class);
3467+ * }
3468+ * </pre>
3469+ *
3470+ * @param type Service interface.
3471+ * @param implementation Service implementation.
3472+ * @return This instance.
3473+ */
3474+ public <T > Jooby bind (final Class <T > type , final Class <? extends T > implementation ) {
3475+ use ((env , conf , binder ) -> {
3476+ binder .bind (type ).to (implementation );
3477+ });
3478+ return this ;
3479+ }
3480+
3481+ /**
3482+ * Bind the provided abstract type to the given implementation:
3483+ *
3484+ * <pre>
3485+ * {
3486+ * bind(MyInterface.class, MyImplementation::new);
3487+ * }
3488+ * </pre>
3489+ *
3490+ * @param type Service interface.
3491+ * @param implementation Service implementation.
3492+ * @return This instance.
3493+ */
3494+ public <T > Jooby bind (final Class <T > type , final Supplier <T > implementation ) {
3495+ use ((env , conf , binder ) -> {
3496+ binder .bind (type ).toInstance (implementation .get ());
3497+ });
3498+ return this ;
3499+ }
3500+
3501+ /**
3502+ * Bind the provided type:
3503+ *
3504+ * <pre>
3505+ * {
3506+ * bind(MyInterface.class);
3507+ * }
3508+ * </pre>
3509+ *
3510+ * @param type Service interface.
3511+ * @return This instance.
3512+ */
3513+ public <T > Jooby bind (final Class <T > type ) {
3514+ use ((env , conf , binder ) -> {
3515+ binder .bind (type );
3516+ });
3517+ return this ;
3518+ }
3519+
3520+ /**
3521+ * Bind the provided type:
3522+ *
3523+ * <pre>
3524+ * {
3525+ * bind(new MyService());
3526+ * }
3527+ * </pre>
3528+ *
3529+ * @param service Service.
3530+ * @return This instance.
3531+ */
3532+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
3533+ public <T > Jooby bind (final Object service ) {
3534+ use ((env , conf , binder ) -> {
3535+ Class type = service .getClass ();
3536+ binder .bind (type ).toInstance (service );
3537+ });
3538+ return this ;
3539+ }
3540+
3541+ /**
3542+ * Bind the provided type and object that requires some type of configuration:
3543+ *
3544+ * <pre>{@code
3545+ * {
3546+ * bind(MyService.class, conf -> new MyService(conf.getString("service.url")));
3547+ * }
3548+ * }</pre>
3549+ *
3550+ * @param type Service type.
3551+ * @param provider Service provider.
3552+ * @return This instance.
3553+ */
3554+ public <T > Jooby bind (final Class <T > type , final Function <Config , ? extends T > provider ) {
3555+ use ((env , conf , binder ) -> {
3556+ T service = provider .apply (conf );
3557+ binder .bind (type ).toInstance (service );
3558+ });
3559+ return this ;
3560+ }
3561+
3562+ /**
3563+ * Bind the provided type and object that requires some type of configuration:
3564+ *
3565+ * <pre>{@code
3566+ * {
3567+ * bind(conf -> new MyService(conf.getString("service.url")));
3568+ * }
3569+ * }</pre>
3570+ *
3571+ * @param type Service type.
3572+ * @param provider Service provider.
3573+ * @return This instance.
3574+ */
3575+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
3576+ public <T > Jooby bind (final Function <Config , T > provider ) {
3577+ use ((env , conf , binder ) -> {
3578+ Object service = provider .apply (conf );
3579+ Class type = service .getClass ();
3580+ binder .bind (type ).toInstance (service );
3581+ });
3582+ return this ;
3583+ }
3584+
34613585 /**
34623586 * Run app in javascript.
34633587 *
0 commit comments