.Net Core 鋒利扩展
中文文档
Status
This project is in very early preview stage and it's not suggested to use it in a real project.
- DI
- AutoMapper
- ElasticSearch
- WebAPiRoute
- EntityFramework Repoistory
First of all need to have a core project at asp.net Core, Here I've created a asp.net core MVC project
Now, install SharpPlugs Core packages
dotnet add package SharpPlug.Core
AddSharpPlugCore during Startup
services.AddSharpPlugCore(opt=>{
opt.DiAssembly.Add(Assembly.GetExecutingAssembly());
});
Now we have the function of the dependency injection, I create a TestService classes with TestService interface
Automatic dependency injection is a naming rules, ends in Service or Repository is automatically injected by default
public class TestService : ITestService,IScopedDependency
{
public string Hello()
{
return "Hello World";
}
}
In the injected ITestService HomeController
public class HomeController : Controller
{
private readonly ITestService _testService;
public HomeController(ITestService testService)
{
_testService = testService;
}
public IActionResult Index()
{
return View();
}
public IActionResult Hello()
{
return Json(_testService.Hello()) ;
}
}
Now press F5 to debug,In your browser's address bar input /home/Hello,The request will be stay in the breakpoint
Now we press F5 to let it continue to run , We will see the Hello World output
Want to know more usage?Please see the advanced document
SharpPlugs is distributed as nuget packages.
Package | Status |
---|---|
SharpPlug.Core | |
SharpPlug.ElasticSearch | |
SharpPlug.AutoMapper | |
SharpPlug.WebApi | |
SharpPlug.EntityFrameworkCore |