This project is read-only.

Sample Mvc Website Walk-Through

Included in the source is a MVC 5.1 Website project that is an example of removing the EntityFramework and Identity EntityFramework references and replacing them with the DynamoDb storage provider. The source of the sample project can be found Source Code /sample and the walk-through can be found here Sample Mvc.

Overview

The sample Mvc web application is a standard web application that uses the Individual User Accounts authentication type. The EntityFramework references have been removed and replaced with the DynamoDb storage provider.

Walk-Through of the SampleMvc

Remove the NuGet packages EntityFramework and Microsoft.AspNet.Identity.EntityFramework packages using the Manage NuGet Packages.
Remove this using statement throughout the application.
using Microsoft.AspNet.Identity.EntityFramework;
Add the NuGet package or the assembly ElCamino.AspNet.Identity.Dynamo to the web application.

Changes to /sample/Models/IdentityModels.cs

Replace the statement
using Microsoft.AspNet.Identity.EntityFramework;
with:
using ElCamino.AspNet.Identity.Dynamo;
using ElCamino.AspNet.Identity.Dynamo.Model;
...
Inherit from the IdentityUser class to provide the base user information and DynamoDb Key mappings.
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    { ...
...
Note: This has changed in 1.0.0.0 Inherit from the IdentityCloudContext which provides the DynamoDb connection and table schema.
    public class ApplicationDbContext : IdentityCloudContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base() { } 
...

Changes to /sample/App_Start/IdentityConfig.cs

Replace the statement
using Microsoft.AspNet.Identity.EntityFramework;
with:
using ElCamino.AspNet.Identity.Dynamo;
...
Adding code to create the DynamoDb tables.
    public class ApplicationUserManager : UserManager<ApplicationUser>
    {
        ...
        public static void Startup()
        {
            //ElCamino - Creates the DynamoDb Tables
            var dynamodbStore = new UserStore<ApplicationUser>(new ApplicationDbContext());
            var createTask = dynamodbStore.CreateTablesIfNotExists();
            createTask.Wait();
            //safe to remove after tables are created once.

        }
...

Changes to /sample/Global.asax.cs

Adding code to create the DynamoDb tables.
protected void Application_Start()
        {
            //ElCamino - Added to create dynamodb tables
            ApplicationUserManager.Startup();
            //
...

Changes to /sample/Web.config

Remove all references to the EntityFramework.
Note: This has changed in 1.0.0.0 Add the default local connection string to the DynamoDb Local Emulator using the custom configuration section. AWS Endpoints are here. New in 1.0.0.0 - use the new TablePrefix property to set a naming prefix for the identity tables that are using in the dynamodb instance.
<configuration>
  <configSections>
    <section name="elcaminoIdentityDynamoDBConfiguration" type="ElCamino.AspNet.Identity.Dynamo.Configuration.IdentityConfigurationSection,ElCamino.AspNet.Identity.Dynamo " />
  </configSections>
  <elcaminoIdentityDynamoDBConfiguration tablePrefix="" serviceURL="http://localhost:8000" />

Remove any deprecated ConnectionStrings
  <connectionStrings>
    <!-- Deprecated ElCamino.AspNet.Identity.Dynamo settings, Important! Remove if using the above config section -->
    <!--<add name="DynamoConnectionString" connectionString="http://localhost:8000" />-->...

Changes to /sample/Web.config

Web.config transformation to use the DynamoDb account key information.
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <!--AWS AccessKeys are not needed if you are using the DynamoDB Local Emulator-->
    <!--Uncomment the AccessKeys section when you connect to a live DynamoDB instance in AWS-->
    <!--and populate with your key values.-->
    <!--
    <add key="AWSAccessKey" value="*** Access Key Id ***" />
    <add key="AWSSecretKey" value="*** Secret Access Key ***" />
    -->
...

Tip: Don't forget to start your Amazon DynamoDB Local Emulator if running locally.

Last edited Sep 26, 2014 at 12:36 AM by dotnetdavy, version 6