Uhmmm I am confused what I did to make this happen.
startup.cs:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Eva804.Data;
using Eva804.Models;
using Eva804.Services;
using System.Globalization;
namespace Eva804
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
var cultureInfo = new CultureInfo("en-AU");
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
app.UseIdentity();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}project.json:
{"userSecretsId": "aspnet-Eva804-c1322fb7-0d41-4f6e-97ca-bb70e4de9d5d","dependencies": {"Microsoft.NETCore.App": {"version": "1.0.1","type": "platform"
},"Microsoft.ApplicationInsights.AspNetCore": "1.0.0","Microsoft.AspNetCore.Authentication.Cookies": "1.0.0","Microsoft.AspNetCore.Diagnostics": "1.0.0","Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0","Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0","Microsoft.AspNetCore.Mvc": "1.0.1","Microsoft.AspNetCore.Razor.Tools": {"version": "1.0.0-preview2-final","type": "build"
},"Microsoft.AspNetCore.Routing": "1.0.1","Microsoft.AspNetCore.Server.IISIntegration": "1.0.0","Microsoft.AspNetCore.Server.Kestrel": "1.0.1","Microsoft.AspNetCore.StaticFiles": "1.0.0","Microsoft.EntityFrameworkCore.SqlServer": "1.0.1","Microsoft.EntityFrameworkCore.SqlServer.Design": {"version": "1.0.1","type": "build"
},"Microsoft.EntityFrameworkCore.Tools": {"version": "1.0.0-preview2-final","type": "build"
},"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0","Microsoft.Extensions.Configuration.Json": "1.0.0","Microsoft.Extensions.Configuration.UserSecrets": "1.0.0","Microsoft.Extensions.Logging": "1.0.0","Microsoft.Extensions.Logging.Console": "1.0.0","Microsoft.Extensions.Logging.Debug": "1.0.0","Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0","Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0","Microsoft.VisualStudio.Web.CodeGeneration.Tools": {"version": "1.0.0-preview2-final","type": "build"
},"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {"version": "1.0.0-preview2-final","type": "build"
}
},"tools": {"BundlerMinifier.Core": "2.0.238","Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final","Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final","Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final","Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final","Microsoft.VisualStudio.Web.CodeGeneration.Tools": {"version": "1.0.0-preview2-final","imports": ["portable-net45+win8"
]
}
},"frameworks": {"netcoreapp1.0": {"imports": ["dotnet5.6","portable-net45+win8"
]
}
},"buildOptions": {"emitEntryPoint": true,"preserveCompilationContext": true
},"runtimeOptions": {"configProperties": {"System.GC.Server": true
}
},"publishOptions": {"include": ["wwwroot","**/*.cshtml","appsettings.json","web.config"
]
},"scripts": {"prepublish": [ "bower install", "dotnet bundle" ],"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}Don't think the context is an issue, but just in case I am missing the obvious.
using Microsoft.EntityFrameworkCore;
using EVA804.Models;
using EVA804.Models.ManageViewModels;
using Eva.Models;
namespace EVA804.Data
{
public class EVAContext : DbContext
{
public EVAContext(DbContextOptions<EVAContext> options) : base(options)
{
}
public DbSet<Outcome> Outcomes { get; set; }
public DbSet<PPE> PPEs { get; set; }
public DbSet<Procedure> Procedures { get; set; }
public DbSet<ProcedureTasks> ProcedureTask { get; set; }
public DbSet<QuoteAssumptions> QuoteAssumption { get; set; }
public DbSet<QuoteExclusions> QuoteExclusion { get; set; }
public DbSet<tTask>tTasks { get; set; }
public DbSet<Condition> Conditions { get; set; }
public DbSet<Equipment> Equipments { get; set; }
public DbSet<Hospital> Hospitals { get; set; }
public DbSet<WaterBody> WaterBodys { get; set; }
public DbSet<Site> Sites { get; set; }
public DbSet<SiteType>SiteTypes {get;set;}
public DbSet<Location> Location { get; set; }
public DbSet<PoolType> PoolTypes { get; set; }
public DbSet<EqType> EqTypes { get; set; }
public DbSet<Construction> Constructions { get; set; }
public DbSet<Make> Makes { get; set; }
public DbSet<HealthCategory> HealthCategorys { get; set; }
public DbSet<HealthFirstAid> HealthFirstAids { get; set; }
public DbSet<HealthGroup> HealthGroups { get; set; }
public DbSet<HealthGroupToAid> HealthGroupToAids { get; set; }
public DbSet<HealthFirstAidKit> HealthFirstAidKits { get; set; }
public DbSet<HealthGroupToKit> HealthGroupToKits { get; set; }
public DbSet<Position> Positions { get; set; }
public DbSet<ContactType> ContactTypes { get; set; }
public DbSet<Client> Clients { get; set; }
public DbSet<ClientContact> ClientContacts { get; set; }
public DbSet<ClientContactDetail> ClientContactDetails { get; set; }
public DbSet<Division> Divisions { get; set; }
public DbSet<Department> Departments { get; set; }
public DbSet<Staff> Staffs { get; set; }
public DbSet<HealthToilet> HealthToilets { get; set; }
public DbSet<HealthWaterTestingFrequency> HealthWaterTestingFrequencys { get; set; }
public DbSet<Job> Job { get; set; }
public DbSet<QuoteRequest> QuoteRequest { get; set; }
public DbSet<Quote> Quote { get; set; }
public DbSet<SiteAccess> SiteAccess { get;set;}
public DbSet<SiteInduction> SiteInductions { get; set; }
public DbSet<SiteTask> SiteTask { get; set; }
public DbSet<PoolTypeTask> PoolTypeTasks { get; set; }
public DbSet<ChemicalHealthTargets> ChemicalHealthTarget { get; set; }
public DbSet<ChemicalOurTargets> ChemicalOurTarget { get; set; }
public DbSet<ChemicalParameter> ChemicalParameters { get; set; }
public DbSet<WaterBodyLog> WaterBodyLogs { get; set; }
public DbSet<WaterTestPerson> WaterTestPersons { get; set; }
public DbSet<ChemicalDirection> ChemicalDirections { get; set; }
public DbSet<ChemicalForm> ChemicalForms { get; set; }
public DbSet<Chemical> Chemical { get; set; }
public DbSet<Frequency> Frequency { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Equipment>()
.Property(d => d.InspectDate)
.HasDefaultValueSql("getDate()");
//modelBuilder.Entity<Job>()
//.Property(d => d.BookingDate)
// .HasDefaultValueSql("getDate()");
modelBuilder.Entity<Job>()
.HasOne(w => w.WaterBody)
.WithMany(w => w.Job)
.OnDelete(GetRestrict());
modelBuilder.Entity<QuoteRequest>()
.HasOne(q => q.Site)
.WithMany(q=>q.QuoteRequest)
.OnDelete(GetRestrict());
modelBuilder.Entity<Site>()
.HasIndex(c => c.Clientid)
.IsUnique(false);
modelBuilder.Entity<SiteInduction>()
.HasOne(q => q.Site)
.WithMany(q=>q.SiteInductions)
.OnDelete(GetRestrict());
modelBuilder.Entity<Condition>().ToTable("Condition");
modelBuilder.Entity<Equipment>().ToTable("Equipment");
modelBuilder.Entity<WaterBody>().ToTable("WaterBody");
modelBuilder.Entity<Site>().ToTable("Site");
modelBuilder.Entity<SiteType>().ToTable("SiteType");
modelBuilder.Entity<Location>().ToTable("Location");
modelBuilder.Entity<PoolType>().ToTable("PoolType");
modelBuilder.Entity<EqType>().ToTable("EqType");
modelBuilder.Entity<Construction>().ToTable("Construction");
modelBuilder.Entity<Make>().ToTable("Make");
modelBuilder.Entity<SiteInduction>().ToTable("SiteInduction");
modelBuilder.Entity<PoolTypeTask>().ToTable("PoolTypeTask");
}
private static Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior GetRestrict()
{
return Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Restrict;
}
public DbSet<Hospital> Hospital { get; set; }
}
}
Error call stack:
System.InvalidOperationException: Unable to resolve service for type 'EVA804.Data.EVAContext' while attempting to activate 'EVA804.Controllers.JobsController'. at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired) at lambda_method(Closure , IServiceProvider , Object[] ) at Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType) at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAllActionFiltersAsync>d__26.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeExceptionFilterAsync>d__25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ApplicationInsights.AspNetCore.ExceptionTrackingMiddleware.<Invoke>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.<Invoke>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__6.MoveNext()
What is causing this issue? Or where do I start to look?