# How should Dry Schema and Validations be prepared with monads?

**URL:** <https://discourse.hanakai.org/t/how-should-dry-schema-and-validations-be-prepared-with-monads/790>\
**Category:** questions\
**Created:** [January 28, 2023, 3:38pm UTC](https://discourse.hanakai.org/t/how-should-dry-schema-and-validations-be-prepared-with-monads/790 "2023-01-28T15:38:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/bkuhlmann/32/475_2.png) [@bkuhlmann](https://discourse.hanakai.org/u/bkuhlmann)\
**Post date:** [January 28, 2023, 3:38pm UTC](https://discourse.hanakai.org/t/how-should-dry-schema-and-validations-be-prepared-with-monads/790/1 "2023-01-28T15:38:29Z")

</div>

Hey. 👋 I was trying to add a provider which would enable monad support for Dry Schema and Validation by default but finding this doesn’t error or work:

```ruby
Hanami.app.register_provider :monads do
  prepare do
    Dry::Schema.load_extensions :monads
    Dry::Validation.load_extensions :monads
  end
end

```

I have to manually load these each time within the source code to make this work but am confused why this can’t prepared by the provider?

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/bkuhlmann/32/475_2.png) [@bkuhlmann](https://discourse.hanakai.org/u/bkuhlmann)\
**Post date:** [March 2, 2023, 9:31pm UTC](https://discourse.hanakai.org/t/how-should-dry-schema-and-validations-be-prepared-with-monads/790/2 "2023-03-02T21:31:03Z")

</div>

I ended up adding this to the application configuration. Example:

```ruby
class App < Hanami::App
  Dry::Schema.load_extensions :monads
  Dry::Validation.load_extensions :monads
end

```

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [March 6, 2023, 10:51am UTC](https://discourse.hanakai.org/t/how-should-dry-schema-and-validations-be-prepared-with-monads/790/3 "2023-03-06T10:51:46Z")

</div>

See the bottom part of my answer here for how I’ve typically done this: [What is the best way to initialize dependencies? - #3 by timriley](https://discourse.hanakai.org/t/what-is-the-best-way-to-initialize-dependencies/802/3)

tl;dr — create a base class in your app that all contracts, etc. inherit from, and put the global configuration in that file.

That way its only loaded when you need it, courtesy of your app’s contracts using it as a parent class.

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/bkuhlmann/32/475_2.png) [@bkuhlmann](https://discourse.hanakai.org/u/bkuhlmann)\
**Post date:** [March 6, 2023, 6:29pm UTC](https://discourse.hanakai.org/t/how-should-dry-schema-and-validations-be-prepared-with-monads/790/4 "2023-03-06T18:29:23Z")

</div>

I opted to respond more fully in this [question](https://discourse.hanakai.org/t/what-is-the-best-way-to-initialize-dependencies/802/4) but thanks for this. 🙇‍♂️ Yeah, I agree, this is a valid solution. A part of me kind of wants to leverage the provider lifecycle more for this because it _feels more consistent_ but maybe that’s just me, though.
