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

EF Configuration

Peter Mbanugo edited this page Jul 13, 2014 · 6 revisions

MembershipReboot allows for flexible store for the user account data. There is an EntityFramework project that implements the appropriate persistence interface. To use this implementation, simply use the DefaultUserAccountRepository class as the constructor parameter to the UserAccountService.

The DefaultUserAccountRepository requires a connection string in the configuration file with the name "MembershipReboot" by default. Here is an example that uses SQL Server Compact for the database (but any other EF compatible provider can be used):

<connectionStrings>
  <add name="MembershipReboot" 
       connectionString="Data Source=|DataDirectory|MembershipReboot.sdf" 
       providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>

But, it can also be configured to use a different connection string name by passing the name to the constructor of DefaultUserAccountRepository class:

<connectionStrings>
  <add name="MyName" 
       connectionString="Data Source=|DataDirectory|MembershipReboot.sdf" 
       providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
public class UserAccount
    {        
        AuthenticationService authService;
        UserAccountService userAccountService;

        public UserAccount()
        {
            var connectionString = "MyName";
            var accountRepo = new DefaultUserAccountRepository(name: connectionString);

            var configuration = new MembershipRebootConfiguration
            {
                EmailIsUsername = true,
                MultiTenant = false,
                RequireAccountVerification = true,
                AllowLoginAfterAccountCreation = true
            };
            configuration.ConfigurePasswordComplexity();

            authService = new SamAuthenticationService(new UserAccountService(configuration,accountRepo));
            userAccountService = authService.UserAccountService;
        }
    }
<connectionStrings>
    <add name="DefaultConnection" 
           connectionString="Data Source=|DataDirectory|MembershipReboot.sdf" 
           providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
//Dependency Injection with Ninject
kernel.Bind<IUserAccountRepository>().To<DefaultUserAccountRepository>().InRequestScope().WithConstructorArgument("name", "DefaultConnection");
Clone this wiki locally