Hook up NetworkTest class with HostController
This commit is contained in:
parent
5ce3d1ce00
commit
10e32001f0
@ -14,10 +14,12 @@ namespace ISPChk.Controllers
|
|||||||
public class HostController : ControllerBase
|
public class HostController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ISPChkContext _context;
|
private readonly ISPChkContext _context;
|
||||||
|
private readonly INetworkTest _networkTest;
|
||||||
|
|
||||||
public HostController(ISPChkContext context)
|
public HostController(ISPChkContext context, INetworkTest networkTest)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_networkTest = networkTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/Host
|
// GET: api/Host
|
||||||
@ -80,6 +82,8 @@ namespace ISPChk.Controllers
|
|||||||
_context.Hosts.Add(host);
|
_context.Hosts.Add(host);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_networkTest.AddHost(host);
|
||||||
|
|
||||||
return CreatedAtAction("GetHost", new { id = host.Id }, host);
|
return CreatedAtAction("GetHost", new { id = host.Id }, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
using System;
|
using ISPChk.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ISPChk
|
namespace ISPChk
|
||||||
{
|
{
|
||||||
interface INetworkTest
|
public interface INetworkTest
|
||||||
{
|
{
|
||||||
|
void AddHost(Host host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,16 @@ namespace ISPChk
|
|||||||
{
|
{
|
||||||
private ISPChkContext _context;
|
private ISPChkContext _context;
|
||||||
|
|
||||||
public NetworkTest()
|
public NetworkTest() {
|
||||||
|
var optionsBuilder = new DbContextOptionsBuilder<ISPChkContext>();
|
||||||
|
optionsBuilder.UseSqlite("Data Source=ispchk.db");
|
||||||
|
_context = new ISPChkContext(optionsBuilder.Options);
|
||||||
|
System.Diagnostics.Debug.WriteLine("NetworkTest instantiated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddHost(Host host)
|
||||||
{
|
{
|
||||||
//_context = new ISPChkContext("Data Source=ispchk.db");
|
System.Diagnostics.Debug.WriteLine("Host added!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ namespace ISPChk
|
|||||||
services.AddDbContext<ISPChkContext>(opt =>
|
services.AddDbContext<ISPChkContext>(opt =>
|
||||||
opt.UseSqlite("Data Source=ispchk.db"));
|
opt.UseSqlite("Data Source=ispchk.db"));
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
services.AddSingleton<INetworkTest, NetworkTest>();
|
var networkTest = new NetworkTest();
|
||||||
|
services.AddSingleton<INetworkTest>(networkTest);
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ISPChk", Version = "v1" });
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ISPChk", Version = "v1" });
|
||||||
|
BIN
ISPChk/ispchk.db
BIN
ISPChk/ispchk.db
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user