Could you please provide some recommendations how to use LightSpeed with custom Membership/Role providers? How can we pass the same LightSpeedContext to CustomMembershipRepository which is used by CustomMembershipProvider?
I am adding simplified classes and I'm marking the problematic place with bolded question marks.
ASP.NET MVC AccountController.cs
namespace Company.Sample.Web.Application.Controllers
{
public class AccountController : MasterController
{
public ActionResult SignIn(System.String username, System.String password, System.String remember, System.String returnUrl)
{
if (Membership.ValidateUser(username, password))
{
System.Boolean createPersistentCookie = false;
System.Boolean.TryParse(remember, out createPersistentCookie);
FormsAuthentication.SetAuthCookie(username, createPersistentCookie);
this.Response.Redirect(returnUrl ?? FormsAuthentication.DefaultUrl);
}
return View();
}
}
}
Web.config
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider" type="Company.Sample.Web.Application.Models.CustomMembershipProvider, Company.Sample.Web.Application.Models"/>
</providers>
</membership>
CustomMembershipProvider.cs
namespace Company.Sample.Web.Application.Models
{
public class CustomMembershipProvider : System.Web.Security.MembershipProvider
{
public ICustomMembershipRepository CustomMembershipRepository { get; set; }
public CustomMembershipProvider()
{
this.CustomMembershipRepository = new CustomMembershipRepository( ????? );
}
public override System.Boolean ValidateUser(System.String username, System.String password)
{
return this.CustomMembershipRepository.Validate(username, password);
}
//...
}
}
ICustomMembershipRepository.cs
namespace Company.Sample.Web.Application.Models
{
public interface ICustomMembershipRepository
{
System.Boolean Validate(System.String username, System.String password);
}
}
CustomMembershipRepository.cs
namespace Company.Sample.Web.Application.Models
{
public class CustomMembershipRepository : RepositoryBase, ICustomMembershipRepository
{
public System.Boolean Validate(System.String username, System.String password)
{
return this.unitOfWorkScope.Current.Users.Where(u => u.UserName == username && u.Password == password).Count() != 0;
}
public CustomMembershipRepository(UnitOfWorkScopeBase<IntegrationUnitOfWork> unitOfWorkScope) : base(unitOfWorkScope)
{
}
}
}