diff --git a/IHP/Assets/ViewFunctions.hs b/IHP/Assets/ViewFunctions.hs index 99a6a60c9..6ab29dc46 100644 --- a/IHP/Assets/ViewFunctions.hs +++ b/IHP/Assets/ViewFunctions.hs @@ -32,7 +32,5 @@ assetPath assetPath = assetPath <> "?v=" <> assetVersion -- The asset version can be configured using the -- @IHP_ASSET_VERSION@ environment variable. assetVersion :: (?context :: ControllerContext) => Text -assetVersion = ?context - |> Config.getFrameworkConfig - |> get #assetVersion +assetVersion = ?context.frameworkConfig.assetVersion {-# INLINABLE assetVersion #-} \ No newline at end of file diff --git a/IHP/Controller/Context.hs b/IHP/Controller/Context.hs index 8712f1944..61a8cd3bc 100644 --- a/IHP/Controller/Context.hs +++ b/IHP/Controller/Context.hs @@ -133,9 +133,9 @@ putContext value = do newtype ActionType = ActionType Typeable.TypeRep -instance ConfigProvider ControllerContext where - getFrameworkConfig context = getFrameworkConfig (get #requestContext context) - {-# INLINABLE getFrameworkConfig #-} +instance HasField "frameworkConfig" ControllerContext FrameworkConfig where + getField controllerContext = controllerContext.requestContext.frameworkConfig + {-# INLINABLE getField #-} -instance LoggingProvider ControllerContext where - getLogger = getLogger . getFrameworkConfig +instance HasField "logger" ControllerContext Logger where + getField controllerContext = controllerContext.frameworkConfig.logger diff --git a/IHP/Controller/Redirect.hs b/IHP/Controller/Redirect.hs index 8d8754f45..28d213856 100644 --- a/IHP/Controller/Redirect.hs +++ b/IHP/Controller/Redirect.hs @@ -43,7 +43,7 @@ redirectTo action = redirectToPath (pathTo action) -- -- Use 'redirectTo' if you want to redirect to a controller action. redirectToPath :: (?context :: ControllerContext) => Text -> IO () -redirectToPath path = redirectToUrl (fromConfig baseUrl <> path) +redirectToPath path = redirectToUrl (?context.frameworkConfig.baseUrl <> path) {-# INLINABLE redirectToPath #-} -- | Redirects to a url (given as a string) diff --git a/IHP/Controller/RequestContext.hs b/IHP/Controller/RequestContext.hs index f78338304..bf6a46ddf 100644 --- a/IHP/Controller/RequestContext.hs +++ b/IHP/Controller/RequestContext.hs @@ -1,7 +1,6 @@ module IHP.Controller.RequestContext ( RequestContext (..) , Respond -, getConfig , RequestBody (..) ) where @@ -28,6 +27,3 @@ data RequestContext = RequestContext , vault :: (Vault.Key (Session IO ByteString ByteString)) , frameworkConfig :: FrameworkConfig } - -instance ConfigProvider RequestContext where - getFrameworkConfig = frameworkConfig diff --git a/IHP/ControllerSupport.hs b/IHP/ControllerSupport.hs index aa4a40f95..99a0dbc3c 100644 --- a/IHP/ControllerSupport.hs +++ b/IHP/ControllerSupport.hs @@ -342,9 +342,7 @@ respondAndExit response = do -- > putStrLn ("Stripe public key: " <> stripePublicKey) -- getAppConfig :: forall configParameter context. (?context :: context, ConfigProvider context, Typeable configParameter) => configParameter -getAppConfig = ?context - |> getFrameworkConfig - |> get #appConfig +getAppConfig = ?context.frameworkConfig.appConfig |> TypeMap.lookup @configParameter |> fromMaybe (error ("Could not find " <> (show (Typeable.typeRep (Typeable.Proxy @configParameter))) <>" in config")) {-# INLINE getAppConfig #-} diff --git a/IHP/ErrorController.hs b/IHP/ErrorController.hs index 0daabd896..d8b08b582 100644 --- a/IHP/ErrorController.hs +++ b/IHP/ErrorController.hs @@ -161,7 +161,7 @@ displayException exception action additionalInfo = do [ recordNotFoundExceptionHandlerProd ] - let allHandlers = if fromConfig environment == Environment.Development + let allHandlers = if ?context.frameworkConfig.environment == Environment.Development then devHandlers else prodHandlers @@ -199,7 +199,7 @@ genericHandler exception controller additionalInfo = do let prodErrorMessage = [hsx|An exception was raised while running the action|] let prodTitle = [hsx|An error happened|] - let (errorMessage, errorTitle) = if fromConfig environment == Environment.Development + let (errorMessage, errorTitle) = if ?context.frameworkConfig.environment == Environment.Development then (devErrorMessage, devTitle) else (prodErrorMessage, prodTitle) let RequestContext { respond } = get #requestContext ?context @@ -211,9 +211,7 @@ postgresHandler exception controller additionalInfo = do let handlePostgresOutdatedError :: Show exception => exception -> H.Html -> IO ResponseReceived handlePostgresOutdatedError exception errorText = do - let ihpIdeBaseUrl = ?context - |> getFrameworkConfig - |> get #ideBaseUrl + let ihpIdeBaseUrl = ?context.frameworkConfig.ideBaseUrl let title = [hsx|Database looks outdated. {errorText}|] let errorMessage = [hsx|