obsidian-micropub/src/factories/ServiceFactory.ts

69 lines
2.0 KiB
TypeScript

import { MicroPluginContainerInterface } from "@base/MicroPluginContainer";
import {
FrontmatterService,
FrontmatterServiceInterface,
FrontmatterServiceDelegate } from "@base/services/FrontmatterService";
import {
TagSynchronizationServiceInterface,
TagSynchronizationService,
TagSynchronizationServiceDelegate
} from "@services/TagSynchronizationService";
export interface ServiceFactoryInterface {
// Builds the synchronization service, used by the client
// to synchronize categories when the plugin is loaded
// and when synchronization is triggered via command.
makeTagSynchronizationService(
delegate?: TagSynchronizationServiceDelegate
): TagSynchronizationServiceInterface
// Builds the yaml frontmatter service, used by the client
// to update the frontmatter of the file after publishing
// with publish date, used tags, etc.
makeFrontmatterService(
delegate?: FrontmatterServiceDelegate
): FrontmatterServiceInterface
}
/*
* Service Factory builds all the Services in the plugin.
* It simplifies building View Models since all the resolved dependencies
* are already available via the factory.
*/
export class ServiceFactory implements ServiceFactoryInterface {
// Properties
private container: MicroPluginContainerInterface
// Life cycle
constructor(
container: MicroPluginContainerInterface
) {
this.container = container
}
// Public
public makeTagSynchronizationService(
delegate?: TagSynchronizationServiceDelegate
): TagSynchronizationServiceInterface {
return new TagSynchronizationService(
this.container.plugin,
this.container.settings,
this.container.networkClient,
this.container.networkRequestFactory,
delegate
)
}
public makeFrontmatterService(
delegate?: FrontmatterServiceDelegate
): FrontmatterServiceInterface {
return new FrontmatterService(
delegate
)
}
}