Yeni bir ASPNET MVC uygulamasında artık AspIdentity güzelliklerini ücretsiz olarak edinebilirsiniz.AspIdentiy ApplicationUserManager Statiktir, nasıl genişletilir, böylece IoC çerçevemde yer alır?
Zararsız küçük bir satır 'e-posta hizmetinizi buraya takın'.
public class EmailService : IIdentityMessageService
{
private static My.Services.IEmailService _emailservice;
public EmailService(Insolvency.Services.IEmailService emailservice)
{
_emailservice = emailservice;
}
public Task SendAsync(IdentityMessage message)
{
_emailservice.SendEmail(message);
return Task.FromResult(0);
}
}
ve şimdi sevinç:
Ve yaptım
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
...
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
:
İçinde Owin tekmeler olarak
public class ApplicationUserManager : UserManager<ApplicationUser>
{
private My.Services.IEmailService _emailservice;
public ApplicationUserManager(IUserStore<ApplicationUser> store, My.Services.IEmailService emailservice): base(store)
{
_emailservice = emailservice;
}
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()), _emailservice);
...
Startup.Auth.cs yılında ApplicationUserManager Oluştur çağırır
ve AutoFac ürününü IoC kapsayıcım olarak kullanıyorum. x.cs
builder.RegisterType<My.Services.EmailService>().As<IEmailService>();
oluştur yöntem statik ise
yüzden alıyorum: http://forums.asp.net/post/5293670.aspx ve How do i create an instance of UserManager ve Using Autofac to provide types exported by static factory:_emailService
boş
Burada baktım
olduğunu. ama şans yok.
Şunu değiştirirsem:
private My.Services.IEmailService _emailservice;
Ben IoC tanrılar başlarını sallayarak hissediyorum statik olmayan herkese açık olmasını ve ben boğuşuyordu kurmak 'nesne referansı gereklidir'
Teşekkürler. Unity ve Autofac arasında dönüşüm yapmaya çalışacağım. – OzBob
Şu anda derleyici hata veriyor: ... 'ApplicationUser' türü, 'Microsoft.AspNet.Identity.EmailTokenProvider' yönteminde 'TUser' türünde parametre türü olarak kullanılamaz. 'ApplicationUser' ile 'Microsoft.AspNet.Identity.IUser ' arasında hiçbir dolaylı başvuru dönüşümü yoktur. IdentityModels.cs –
OzBob
için kaynağınızı yaptırabilirsiniz. – free4ride