66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using Matrix42.Extensions.Scaffolder.Core.Project;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Matrix42.Extensions.Scaffolder.Core.Functionality
|
|
{
|
|
public sealed class WebApiFunctionalityDefinition : IProjectFunctionalityDefinition
|
|
{
|
|
public ProjectFunctionality Kind => ProjectFunctionality.WebApi;
|
|
|
|
public IEnumerable<TemplateFile> GetFiles(
|
|
ExtensionScaffoldingOptions options,
|
|
ProjectDefinition project)
|
|
{
|
|
var ns = options.ExtensionNamespace;
|
|
|
|
yield return new TemplateFile
|
|
{
|
|
RelativePath = @"Controllers\TestController.cs",
|
|
Content = WebApi_TestControllerTemplate.Replace("{ns}", ns),
|
|
CreateIfMissingOnly = true
|
|
};
|
|
}
|
|
|
|
public IEnumerable<ProjectReferenceDefinition> GetReferences(ExtensionScaffoldingOptions options, ProjectDefinition project)
|
|
{
|
|
yield return new ProjectReferenceDefinition
|
|
{
|
|
Include = "Matrix42.WebApi.Contracts",
|
|
HintPath = @"..\..\..\..\Root\bin\Matrix42.WebApi.Contracts.dll"
|
|
};
|
|
|
|
yield return new ProjectReferenceDefinition
|
|
{
|
|
Include = "Matrix42.Hosting.Contracts",
|
|
HintPath = @"..\..\..\..\Root\bin\Matrix42.Hosting.Contracts.dll"
|
|
};
|
|
}
|
|
|
|
private const string WebApi_TestControllerTemplate =
|
|
@"
|
|
using Matrix42.WebApi.Contracts;
|
|
using Matrix42.Hosting.Contracts;
|
|
|
|
namespace {ns}.Services
|
|
{
|
|
[RoutePrefix(""api/test"")]
|
|
public class TestController : ApiController
|
|
{
|
|
private readonly IDependencyResolver _resolver;
|
|
|
|
public TestController(IDependencyResolver resolver)
|
|
{
|
|
_resolver = resolver;
|
|
}
|
|
|
|
[HttpPost, Route(""test"")]
|
|
public string TestMethod()
|
|
{
|
|
// TODO: implement your test method logic
|
|
return ""OK"";
|
|
}
|
|
}
|
|
}";
|
|
}
|
|
}
|