Some checks failed
Create and publish a Docker image / Publish image (push) Failing after 4m3s
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
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" });
|
|
} |