tugberkugurlu / AspNet.Identity.RavenDB

Fully asynchronous, new and sweet ASP.NET Identity implementation for RavenDB
MIT License
42 stars 28 forks source link

Optimistic Concurrency AutoFAC #40

Open p10tyr opened 9 years ago

p10tyr commented 9 years ago

I upgraded to RavenDB 3 and updated to Identity PRE6

You suggest this

IDocumentStore documentStore = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "AspNetIdentity" }.Initialize();

using (IAsyncDocumentSession session = documentStore.OpenAsyncSession()) { session.Advanced.UseOptimisticConcurrency = true; RavenUserStore ravenUserStore = new RavenUserStore(session); UserManager userManager = new UserManager(ravenUserStore);

// UserManager<RavenUser> is ready to use!

}

But I am using AutoFAC and I get the error: Optimistic concurrency disabled 'IAsyncDocumentSession' instance is not supported be......

On this line. How Do I set what is needed?

builder.Register(c => new RavenUserStore(c.Resolve(), false)).As<IUserStore>().InstancePerHttpRequest();

So the setting is on this line in autofac

builder.Register(c => c.Resolve().OpenAsyncSession()).As().InstancePerHttpRequest();

But how can I set .Advanced.UseOptimisticConcurrency = true ?

tugberkugurlu commented 9 years ago

try:

builder.Register(c => 
{
    IAsyncDocumentSession session = documentStore.OpenAsyncSession()
    session.Advanced.UseOptimisticConcurrency = true;

    return session;

}).As().InstancePerHttpRequest();
p10tyr commented 9 years ago

Ahh Great. Thanks for the tip. I was unsure on how to do that. I was looking at Property Injection, AutoWire Types and stuff. I will remember now that I can use {} in Lambas like that. Very Usefull.

This is the compilable solution.

   builder.Register(c => 
            {
                IAsyncDocumentSession session = c.Resolve<IDocumentStore>().OpenAsyncSession();
                session.Advanced.UseOptimisticConcurrency = true;
                return session;
            })
            .As<IAsyncDocumentSession>() .InstancePerHttpRequest();