Skip to content

Commit

Permalink
Change application, add prepare() method
Browse files Browse the repository at this point in the history
A shorthand method for configuring the application using a default configurator, with specified configuration source.
  • Loading branch information
aedart committed Oct 6, 2024
1 parent 571f547 commit 9760e09
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/contracts/src/core/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {
Callback,
ClassMethodReference
} from "@aedart/contracts";
import { Source } from "@aedart/contracts/config";
import { Container } from "@aedart/contracts/container";
import { CallbackWrapper } from "@aedart/contracts/support";
import {
Registrar,
ServiceProvider,
ServiceProviderConstructor,
BootException,
} from "@aedart/contracts/support/services";
import {
ConfiguratorCallback,
Expand All @@ -30,6 +30,29 @@ import BootstrapperConstructor from "./BootstrapperConstructor";
*/
export default interface Application extends Container
{
/**
* Prepare this application using the given configuration source.
*
* **Note**: _Method is shorthand for [configuring]{@link configure} this application
* using a default {@link Configurator} with a configuration {@link Source}:_
*
* @example
* const source = {}; // not shown here...
*
* // Prepare using configuration source
* app.prepare(source);
*
* // Above is equivalent to:
* app.configure( (configurator) => configurator.with(...) )
*
* @param {Source} using
*
* @returns {this}
*
* @see {Configurator.with}
*/
prepare(using: Source): this;

/**
* Configure this application using given configurator
*
Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isPromise,
isCallable
} from "@aedart/support/reflections";
import type { Source } from "@aedart/contracts/config";
import { isConfigurator } from "./configuration/isConfigurator";
import { isConfiguratorConstructor } from "./configuration/isConfiguratorConstructor";
import ConfigurationError from "./exceptions/ConfigurationError";
Expand Down Expand Up @@ -149,6 +150,34 @@ export default class Application extends Container implements ApplicationContrac
return super.setInstance(container) as ApplicationContract | null;
}

/**
* Prepare this application using the given configuration source.
*
* **Note**: _Method is shorthand for [configuring]{@link configure} this application
* using a default {@link Configurator} with a configuration {@link Source}:_
*
* @example
* const source = {}; // not shown here...
*
* // Prepare using configuration source
* app.prepare(source);
*
* // Above is equivalent to:
* app.configure( (configurator) => configurator.with(...) )
*
* @param {Source} using
*
* @returns {this}
*
* @see {Configurator.with}
*/
public prepare(using: Source): this
{
return this.configure(
(configurator) => configurator.with(using)
);
}

/**
* Configure this application using given configurator
*
Expand Down

0 comments on commit 9760e09

Please sign in to comment.