ClawjectFactoryโ
It's a factory class that creates a ClawjectApplicationContext instance.
Creating a ClawjectApplicationContextโ
To create a new ClawjectApplicationContext
instance, you need to pass the class that is the root class of your application.
This class is the class that contains the @ClawjectApplication
decorator.
Method createApplicationContext
returns a promise that resolves to a newly created ClawjectApplicationContext
instance.
import { ClawjectFactory, ClawjectApplication } from '@clawject/di';
@ClawjectApplication
class Application {
// ...
}
const applicationContext = await ClawjectFactory.createApplicationContext(Application);
If application class contains constructor, you should pass the constructor arguments as the second parameter to createApplicationContext
.
Constructor arguments can be either:
- Array of constructor arguments
- Function that returns an array of values
- Function that returns a Promise that resolves to an array of values
import { ClawjectFactory, ClawjectApplication } from '@clawject/di';
@ClawjectApplication
class Application {
constructor(
private someConfigurationValue: string
) {}
}
// Pass an array of values
ClawjectFactory.createApplicationContext(Application, ['some value']);
// Pass a function that returns an array of values
ClawjectFactory.createApplicationContext(Application, () => ['some value'] as const);
// Pass a function that returns a Promise that resolves to an array of values
ClawjectFactory.createApplicationContext(Application, async () => {
const configurationValue = await fetchValue('https://...');
return [configurationValue] as const;
});