Skip to content

Commit

Permalink
Removed further references to ConfigProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Oct 17, 2022
1 parent e82af66 commit 400f91f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
9 changes: 6 additions & 3 deletions Guide/controller.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ This will render `Hello World, Unnamed!` when the `ExampleAction` is called with

### Accessing the FrameworkConfig inside Controllers and Views.

The config defined in `Config/Config.hs` is available through the implicit parameter `context`, a [`ConfigProvider`](https://ihp.digitallyinduced.com/api-docs/IHP-FrameworkConfig.html#t:ConfigProvider) that is available in controllers.
The config defined in `Config/Config.hs` is available through the implicit parameter `?context` that is available in controllers:

```haskell
action MyAction = do
let config = ?context.frameworkConfig
```

There are helpers that use this implicit parameter, e.g. [`isDevelopment`](https://ihp.digitallyinduced.com/api-docs/IHP-FrameworkConfig.html#v:isDevelopment)/[`isProduction`](https://ihp.digitallyinduced.com/api-docs/IHP-FrameworkConfig.html#v:isProduction):

Expand All @@ -168,8 +173,6 @@ action MyAction = do
when isDevelopment (putStrLn "Running in dev mode")
```

or you can use the function [`getFrameworkConfig`](https://ihp.digitallyinduced.com/api-docs/IHP-FrameworkConfig.html#v:getFrameworkConfig) if you need to access the config yourself.

### Advanced: Working with Custom Types

Rarely you might want to work with a custom scalar value which is not yet supported with [`param`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Param.html#v:param). Define a custom [`ParamReader`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Param.html#t:ParamReader) instance to be able to use the [`param`](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Param.html#v:param) functions with your custom value type. [For that, take a look at the existing instances of `ParamReader`.](https://ihp.digitallyinduced.com/api-docs/IHP-Controller-Param.html#t:ParamReader)
Expand Down
4 changes: 1 addition & 3 deletions IHP/DataSync/Role.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,4 @@ grantPermissions role = do
pure ()

authenticatedRole :: (?context :: context, ConfigProvider context) => Text
authenticatedRole = ?context
|> getFrameworkConfig
|> get #rlsAuthenticatedRole
authenticatedRole = ?context.frameworkConfig.rlsAuthenticatedRole
2 changes: 1 addition & 1 deletion IHP/FrameworkConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ data FrameworkConfig = FrameworkConfig
-- > import Config -- For accessing the RedisUrl data type
-- >
-- > action MyAction = do
-- > let appConfig = ?context |> getFrameworkConfig |> get #appConfig
-- > let appConfig = ?context.frameworkConfig.appConfig
-- > let (RedisUrl redisUrl) = appConfig
-- > |> TMap.lookup @RedisUrl
-- > |> fromMaybe (error "Could not find RedisUrl in config")
Expand Down
4 changes: 2 additions & 2 deletions IHP/Test/Mocking.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import qualified IHP.AutoRefresh.Types as AutoRefresh
import qualified IHP.Controller.Context as Context
import IHP.Controller.RequestContext (RequestBody (..), RequestContext (..))
import IHP.ControllerSupport (InitControllerContext, Controller, runActionWithNewContext)
import IHP.FrameworkConfig (ConfigBuilder (..), FrameworkConfig (..), getFrameworkConfig)
import IHP.FrameworkConfig (ConfigBuilder (..), FrameworkConfig (..))
import qualified IHP.FrameworkConfig as FrameworkConfig
import IHP.ModelSupport (createModelContext, Id')
import IHP.Prelude
Expand Down Expand Up @@ -153,7 +153,7 @@ callActionWithParams controller params = do
--
callJob :: forall application job. (ContextParameters application, Typeable application, Job job) => job -> IO ()
callJob job = do
let frameworkConfig = getFrameworkConfig ?context
let frameworkConfig = ?context.frameworkConfig
let ?context = frameworkConfig
perform job

Expand Down

0 comments on commit 400f91f

Please sign in to comment.