Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Fixing dotnet ef database update
Browse files Browse the repository at this point in the history
Currently it is impossible to create database for the chat sample - `dotnet ef` commands fail with: "No parameterless constructor was found on 'ApplicationDbContext'. Either add a parameterless constructor to 'Application
DbContext' or add an implementation of 'IDbContextFactory<ApplicationDbContext>' in the same assembly as 'ApplicationDbC
ontext'." - adding IDbContextFactory implementation to fix this

Also disabling Redis presence in favor of in-memory presence
  • Loading branch information
moozzyk committed May 15, 2017
1 parent ef7a351 commit 8b455ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
25 changes: 25 additions & 0 deletions samples/ChatSample/Data/ApplicationDbContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;

namespace ChatSample.Data
{
public class ApplicationDbContextFactory : IDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext Create(string[] args)
{
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory()))
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseSqlServer(configurationBuilder.Build().GetConnectionString("DefaultConnection"));

return new ApplicationDbContext(optionsBuilder.Options);
}
}
}
14 changes: 7 additions & 7 deletions samples/ChatSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ public void ConfigureServices(IServiceCollection services)

// To use Redis scaleout uncomment .AddRedis and uncomment Redis related lines below for presence
services.AddSignalR()
.AddRedis()
//.AddRedis()
;
services.AddAuthentication();


//services.AddSingleton(typeof(DefaultHubLifetimeManager<>), typeof(DefaultHubLifetimeManager<>));
//services.AddSingleton(typeof(HubLifetimeManager<>), typeof(DefaultPresenceHublifetimeMenager<>));
//services.AddSingleton(typeof(IUserTracker<>), typeof(InMemoryUserTracker<>));
services.AddSingleton(typeof(DefaultHubLifetimeManager<>), typeof(DefaultHubLifetimeManager<>));
services.AddSingleton(typeof(HubLifetimeManager<>), typeof(DefaultPresenceHublifetimeMenager<>));
services.AddSingleton(typeof(IUserTracker<>), typeof(InMemoryUserTracker<>));

services.AddSingleton(typeof(RedisHubLifetimeManager<>), typeof(RedisHubLifetimeManager<>));
services.AddSingleton(typeof(HubLifetimeManager<>), typeof(RedisPresenceHublifetimeMenager<>));
services.AddSingleton(typeof(IUserTracker<>), typeof(RedisUserTracker<>));
//services.AddSingleton(typeof(RedisHubLifetimeManager<>), typeof(RedisHubLifetimeManager<>));
//services.AddSingleton(typeof(HubLifetimeManager<>), typeof(RedisPresenceHublifetimeMenager<>));
//services.AddSingleton(typeof(IUserTracker<>), typeof(RedisUserTracker<>));
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down

0 comments on commit 8b455ec

Please sign in to comment.