1.0.0-rc.30 • Published 3 months ago
@exobase/use-services v1.0.0-rc.30
title: 'useServices' description: 'A hook inject needed services into an Exobase function'
group: 'Hooks'
Provides an Exobase hook that allows for pseudo dependency injection of endpoint function dependencies into the services
property of the Props
argument.
Install
yarn add @exobase/use-services
# or
yarn add @exobase/hooks
Import
import { useServices } from '@exobase/use-services'
// or
import { useServices } from '@exobase/hooks'
Usage
To keep your endpoint functions easy to test, use the useServices
hook to pass modules that own the interface to an external resources (database, cache, or a third-party app) as a function argument.
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useExpress } from '@exobase/use-express'
import { useServices } from '@exobase/use-services'
type Args = {}
type Services = {
database: Database
cache: Cache
stripe: Stripe
github: GitHub
}
const setupAccount = ({ services }: Props<Args, Services>) => {
const { database, cache, stripe, github } = services
const customer = await database.customers.get()
const paymentData = await stripe.setup(customer)
await github.cloneRepository(customer)
await cache.put(customer)
}
export default compose(
useExpress(),
useServices({
database: () => new Database(),
cache: () => new Cache(),
stripe: () => new Stripe(),
github: () => new GitHub()
}),
setupAccount
)
1.0.0-rc.30
3 months ago
1.0.0-rc.29
3 months ago
1.0.0-rc.28
3 months ago
1.0.0-rc.27
3 months ago
1.0.0-rc.26
3 months ago
1.0.0-rc.24
1 year ago
1.0.0-rc.23
1 year ago
1.0.0-rc.22
1 year ago
1.0.0-rc.21
1 year ago
1.0.0-rc.20
1 year ago
1.0.0-rc.19
1 year ago
1.0.0-rc.13
1 year ago
1.0.0-rc.17
1 year ago
1.0.0-rc.16
1 year ago
1.0.0-rc.15
1 year ago
1.0.0-rc.14
1 year ago
1.0.0-rc.18
1 year ago
1.0.0-rc.12
1 year ago
1.0.0-rc.11
1 year ago
1.0.0-rc.10
1 year ago
1.0.0-rc.9
1 year ago
1.0.0-rc.8
1 year ago
1.0.0-rc.7
1 year ago
1.0.0-rc.6
2 years ago
1.0.0-rc.5
2 years ago
1.0.0-rc.4
2 years ago
1.0.0-rc.3
2 years ago
1.0.0-rc.2
2 years ago