For the complete documentation index, see llms.txt. This page is also available as Markdown.

Builtins and Services

Understanding plugin builtin and container services from Discussions module instances, validators and command dependencies.

Builtins are objects in the plugin tree and their assembly descriptions, and services are capabilities resolved through the container. A module instance can be referenced by the plugin tree at the same time and organize business objects through its own service container.

Reuse Existing Objects

Source: src/Zongsoft.Discussions.plugin (excerpt; see source for context).

Zongsoft.Discussions.plugin
<extension path="/Workbench/Modules">
	<object name="Discussions" value="{static:Zongsoft.Discussions.Module.Current, Zongsoft.Discussions}">
		<expose name="Accessor" value="{path:../@Accessor}">
			<expose name="Filters" value="{path:../@Filters}" />
		</expose>

		<expose name="Events" value="{path:../@Events}" />
		<expose name="Properties" value="{path:../@Properties}" />
	</object>
</extension>

Use value here to refer to the existing Module.Current to avoid creating a second module. The type form is used to let the builder create new objects; validators and filters use this method.

Services Are Discovered from Assembly

Source: src/Services/ForumService.cs (excerpt; see source for context).

ForumService.cs
[Service(nameof(ForumService))]
[DataService(typeof(ForumCriteria))]
public class ForumService : DataServiceBase<Forum>
{
	#region 构造函数
	public ForumService(IServiceProvider serviceProvider) : base(serviceProvider) { }

After the assembly is loaded and scanned, the Service attribute description is registered. The constructor of ForumService receives the service provider, and subsequent accessors and associated services use this scope.

Commands Depend on Business Services

Source: src/Services/Commands/MessageSendCommand.cs (excerpt; see source for context).

Property injection specifies the Discussions module provider. The existence of the command class does not mean that it has entered the terminal command tree; currently Discussions.plugin does not mount MessageSendCommand, so you cannot directly fabricate a executable send command tutorial. See Commands for the actual logic of the command itself.

Lifecycle and Ownership

Don't put request identities into shared builtin, and don't release container-owned services incrementally. Explicit calling context should be used when stateful operations are required. When the service cannot be found, first determine whether the failure occurred in the assembly scanning, module selection or builtin injection stage. For details, see service resolution.

Last updated