Добавил систему плагинов
Some checks failed
Create and publish a Docker image / Publish image (push) Failing after 4m3s
Some checks failed
Create and publish a Docker image / Publish image (push) Failing after 4m3s
This commit is contained in:
45
SfeduSchedule.Plugin.Sample/Plugin.cs
Normal file
45
SfeduSchedule.Plugin.Sample/Plugin.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SfeduSchedule.Plugin.Abstractions;
|
||||
|
||||
namespace SfeduSchedule.Plugin.Sample;
|
||||
|
||||
// Пример сервиса плагина
|
||||
public interface IGreeter
|
||||
{
|
||||
string Greet(string name);
|
||||
}
|
||||
|
||||
public sealed class Greeter : IGreeter
|
||||
{
|
||||
public string Greet(string name) => $"Hello, {name} from {nameof(Plugin)}!";
|
||||
}
|
||||
|
||||
public sealed class SamplePlugin : IPlugin
|
||||
{
|
||||
public string Name => "Sample";
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Регистрируем DI-сервисы плагина
|
||||
services.AddScoped<IGreeter, Greeter>();
|
||||
// Можно регистрировать любые IHostedService, Options и т.д.
|
||||
}
|
||||
|
||||
public void MapEndpoints(IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
// Пример Minimal API эндпоинта
|
||||
endpoints.MapGet("/plugins/sample/hello", (IGreeter greeter) =>
|
||||
{
|
||||
return Results.Ok(new { message = greeter.Greet("world") });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Пример MVC-контроллера из плагина
|
||||
[ApiController]
|
||||
[Route("plugins/sample/[controller]")]
|
||||
public class EchoController : ControllerBase
|
||||
{
|
||||
[HttpGet("{text}")]
|
||||
public IActionResult Get(string text) => Ok(new { echo = text, from = "Plugin.Sample" });
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SfeduSchedule.Plugin.Sample.plugin</AssemblyName>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<!-- Кладём зависимости плагина рядом со сборкой, чтобы загрузчик их нашёл -->
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Даёт доступ к Microsoft.AspNetCore.* (ControllerBase и т.п.) -->
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
|
||||
<ProjectReference Include="..\SfeduSchedule.Plugin.Abstractions\SfeduSchedule.Plugin.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user