fix repo handling of dbcontext, ingore some resharper optimizations

This commit is contained in:
Collin M. Barrett 2017-04-10 10:32:02 -05:00
parent 940f0b8327
commit 28663bd0a8
12 changed files with 27 additions and 39 deletions

View file

@ -1,6 +1,4 @@
using System.Collections.Generic;
using FilterLists.Models;
using FilterLists.Services;
using FilterLists.Services;
using Microsoft.AspNetCore.Mvc;
namespace FilterLists.Api.Controllers
@ -17,35 +15,10 @@ public ListsController(IListService listService)
// GET api/lists
[HttpGet]
public IEnumerable<List> Get()
public JsonResult Get()
{
var result = _listService.GetAll();
var result = Json(_listService.GetAll());
return result;
}
// GET api/lists/5
[HttpGet("{id}")]
public string Get(int id)
{
return "list";
}
// POST api/lists
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/lists/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/lists/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

View file

@ -4,6 +4,7 @@ namespace FilterLists.Api.DependencyInjection.Extensions
{
public static class ConfigureServicesCollection
{
// ReSharper disable once UnusedMethodReturnValue.Global
public static IServiceCollection RegisterFilterListsApi(this IServiceCollection services)
{
services.AddMvc();

View file

@ -3,8 +3,11 @@
namespace FilterLists.Api
{
// ReSharper disable once UnusedMember.Global
public class Program
{
// ReSharper disable once UnusedMember.Global
// ReSharper disable once UnusedParameter.Global
public static void Main(string[] args)
{
var host = new WebHostBuilder()

View file

@ -9,6 +9,7 @@
namespace FilterLists.Api
{
// ReSharper disable once ClassNeverInstantiated.Global
public class Startup
{
public Startup(IHostingEnvironment env)
@ -21,6 +22,7 @@ public Startup(IHostingEnvironment env)
Configuration = builder.Build();
}
// ReSharper disable once MemberCanBePrivate.Global
public IConfigurationRoot Configuration { get; }
public void ConfigureServices(IServiceCollection services)

View file

@ -11,6 +11,7 @@ public FilterListsDbContext(DbContextOptions options)
{
}
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public DbSet<List> List { get; set; }
}
}

View file

@ -11,6 +11,7 @@ namespace FilterLists.Data.DependencyInjection.Extensions
{
public static class ConfigureServicesCollection
{
// ReSharper disable once UnusedMethodReturnValue.Global
public static IServiceCollection RegisterFilterListsRepositories(this IServiceCollection services,
IConfiguration configuration)
{

View file

@ -14,4 +14,8 @@
<ProjectReference Include="..\FilterLists.Models\FilterLists.Models.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Stored Procedures\" />
</ItemGroup>
</Project>

View file

@ -3,26 +3,22 @@
using FilterLists.Data.Contexts;
using FilterLists.Data.Contracts.Repositories;
using FilterLists.Models;
using Microsoft.EntityFrameworkCore;
namespace FilterLists.Data.Repositories
{
// ReSharper disable once ClassNeverInstantiated.Global
public class ListRepository : IListRepository
{
private readonly DbContextOptions _options;
private readonly FilterListsDbContext _filterListsDbContext;
public ListRepository(DbContextOptions options)
public ListRepository(FilterListsDbContext filterListsDbContext)
{
_options = options;
_filterListsDbContext = filterListsDbContext;
}
public IEnumerable<List> GetAll()
{
using (var context = new FilterListsDbContext(_options))
{
context.Database.OpenConnection();
return context.List.AsEnumerable();
}
return _filterListsDbContext.List.AsEnumerable();
}
}
}

View file

@ -4,9 +4,11 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
namespace FilterLists.Models
{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public abstract class BaseEntity
{
[Key]

View file

@ -1,7 +1,10 @@
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
namespace FilterLists.Models
{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
// ReSharper disable once ClassNeverInstantiated.Global
public class List : BaseEntity
{
[MaxLength(512)]

View file

@ -5,6 +5,7 @@ namespace FilterLists.Services.DependencyInjection.Extensions
{
public static class ConfigureServicesCollection
{
// ReSharper disable once UnusedMethodReturnValue.Global
public static IServiceCollection RegisterFilterListsServices(this IServiceCollection services)
{
services.TryAddScoped<IListService, ListService>();

View file

@ -4,6 +4,7 @@
namespace FilterLists.Services
{
// ReSharper disable once ClassNeverInstantiated.Global
public class ListService : IListService
{
private readonly IListRepository _listRepository;