Skip to content

Commit

Permalink
Implement with() and withConfiguration()
Browse files Browse the repository at this point in the history
Still missing a way to populate the configuration repository. For now, items can be added into the configurator.
  • Loading branch information
aedart committed Oct 2, 2024
1 parent a787641 commit a8509bd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/core/src/configuration/BaseConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
IdentifierAliasTuple,
IdentifierInstanceTuple
} from "@aedart/contracts/container";
import { shallowMerge } from "@aedart/support/objects";
import ConfigurationError from "../exceptions/ConfigurationError";

/**
Expand All @@ -34,6 +35,15 @@ export default abstract class BaseConfigurator implements Configurator {
*/
protected app: Application | undefined;

/**
* Configuration items for the application
*
* @type {Record<PropertyKey, any>}
*
* @protected
*/
protected configurationItems: Record<PropertyKey, any> = {};

/**
* List of bindings to be registered
*
Expand Down Expand Up @@ -117,6 +127,32 @@ export default abstract class BaseConfigurator implements Configurator {

return this;
}

/**
* Alias for {@see withConfiguration}
*
* @param {Record<PropertyKey, any>} items
*
* @return {this}
*/
public with(items: Record<PropertyKey, any>): this /* eslint-disable-line @typescript-eslint/no-explicit-any */
{
return this.withConfiguration(items);
}

/**
* Add configuration items for the application
*
* @param {Record<PropertyKey, any>} items
*
* @return {this}
*/
public withConfiguration(items: Record<PropertyKey, any>): this /* eslint-disable-line @typescript-eslint/no-explicit-any */
{
this.configurationItems = shallowMerge(this.configurationItems, items);

return this;
}

/**
* Add "core" bindings to be registered
Expand Down

0 comments on commit a8509bd

Please sign in to comment.