| 1 | import React, { createContext, useContext } from "react"; |
| 2 | |
| 3 | import { ServiceContainer } from "./ServiceContainer.js"; |
| 4 | |
| 5 | import { serviceContainer as defaultContainer } from "./index.js"; |
| 6 | |
| 7 | const ServiceContainerContext = |
| 8 | createContext<ServiceContainer>(defaultContainer); |
| 9 | |
| 10 | export function ServiceContainerProvider({ |
| 11 | children, |
| 12 | container = defaultContainer, |
| 13 | }: { |
| 14 | children: React.ReactNode; |
| 15 | container?: ServiceContainer; |
| 16 | }) { |
| 17 | return ( |
| 18 | <ServiceContainerContext.Provider value={container}> |
| 19 | {children} |
| 20 | </ServiceContainerContext.Provider> |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | export function useServiceContainer() { |
| 25 | return useContext(ServiceContainerContext); |
| 26 | } |