diff --git a/Guide/controller.markdown b/Guide/controller.markdown index 0ac9c1412..bbb57a32f 100644 --- a/Guide/controller.markdown +++ b/Guide/controller.markdown @@ -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): @@ -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) diff --git a/IHP/DataSync/Role.hs b/IHP/DataSync/Role.hs index fcfc4ce27..5856a3044 100644 --- a/IHP/DataSync/Role.hs +++ b/IHP/DataSync/Role.hs @@ -70,6 +70,4 @@ grantPermissions role = do pure () authenticatedRole :: (?context :: context, ConfigProvider context) => Text -authenticatedRole = ?context - |> getFrameworkConfig - |> get #rlsAuthenticatedRole \ No newline at end of file +authenticatedRole = ?context.frameworkConfig.rlsAuthenticatedRole \ No newline at end of file diff --git a/IHP/FrameworkConfig.hs b/IHP/FrameworkConfig.hs index 38d828ba6..2bfff0bbe 100644 --- a/IHP/FrameworkConfig.hs +++ b/IHP/FrameworkConfig.hs @@ -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") diff --git a/IHP/Test/Mocking.hs b/IHP/Test/Mocking.hs index ef30372db..696caf073 100644 --- a/IHP/Test/Mocking.hs +++ b/IHP/Test/Mocking.hs @@ -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 @@ -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