ASP.NET5 500 Error when using the repository pattern
<p><strong>Edit 3:</strong> I don't know what I did to fix this, but my problem went away. I think the most important things I found, and to take away if you have this issue is that in ASP.NET 5 MVC 6 we have to add middleware for almost everything, including the developer error pages using <code>app.UseDeveloperExceptionPage();</code>... after that I realized that the stack trace might be referring to other classes referenced from within the controller such as the repository and the context object, in my case. I messed with them a bit but I don't remember changing anything drastic. I think I may have had a typo in the constructor of my repository class.</p>

<p>I'm getting a 500 Internal Server Error with the controller, but it displays the static json data without the constructor just fine. I suspect there is something going wrong with the built-in dependency injection but I can't figure it out as I'm not getting any errors or warnings during build.</p>

<p>Edit: I see absolutely <em>nothing</em> in browser when navigationg to <code>http://localhost:5000/api/blogpost/</code>. Just a blank page. No Error. No nothing. Using Postman to send the HTTP request, I get error code 500. Again, by commenting out the constructor I see <code>{"name":"Cameron"}</code>, and get code 200 OK in both browser and Postman. There are no exceptions within VS, and there are no errors in the Output console either.</p>

<p>Edit 2: I found the middleware <code>app.UseDeveloperExceptionPage();</code> and it produces <code>MissingMethodException: No parameterless constructor defined for this object.</code> - If I make a parameterless constructor, it produces: <code>InvalidOperationException: Multiple constructors accepting all given argument types have been found in type 'MyApp.Controllers.BlogPostController'. There should only be one applicable constructor.</code> - It seems like something whacky is going on with ASP.NET5's dep injection?</p>

<p>Here's my controller:</p>

<pre><code>using MyApp.Data.Repository;
using MyApp.Models;
using Microsoft.AspNet.Mvc;
using System;

    namespace MyApp.Controllers
    {
        [Route("api/[controller]")]
        public class BlogPostController : Controller
        {
            // If I comment out this var and the constructor this works.
            private IBlogPostRepository _repository;

            // If I leave them here, I get a 500 Internal Server Error.
            // If I set a breakpoint here, it never fires.
            // If I create a constructor that takes zero args, it never fires.
            // I do not get any errors.
            public BlogPostController(IBlogPostRepository repository)
            {
                _repository = repository;
            }

            [HttpGet]
            public JsonResult Get()
            {
                return Json(new { name = "Cameron" });
            }
        }
    }
</code></pre>

<p>Here is Startup.cs ConfigureServices:</p>

<pre><code>public void ConfigureServices(IServiceCollection services)
{
    // MVC 6
    services.AddMvc();

    // EntityFramework 7
    services.AddEntityFramework()
        .AddSqlServer()
        .AddDbContext&lt;AppDbContext&gt;(options =&gt;
        {
            // Will use the last Data:DefaultConnection:ConnectionString
            // that was loaded from the config files in the constructor.
            options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]);
        });

    // Injections
    services.AddTransient&lt;AppDbContextSeedData&gt;();
    services.AddScoped&lt;IBlogPostRepository, BlogPostRepository&gt;();
}
</code></pre>