Skip to content

Added RavenUserAuthRepository for RavenDB authentication support#18

Merged
mythz merged 1 commit intoServiceStackV3:masterfrom
sgraphics:master
Jan 9, 2013
Merged

Added RavenUserAuthRepository for RavenDB authentication support#18
mythz merged 1 commit intoServiceStackV3:masterfrom
sgraphics:master

Conversation

@sgraphics
Copy link
Copy Markdown
Contributor

Usage in an MVC environment:

container.Register<IUserAuthRepository>(c => new RavenUserAuthRepository(MvcApplication.Store));

mythz added a commit that referenced this pull request Jan 9, 2013
Added RavenUserAuthRepository for RavenDB authentication support
@mythz mythz merged commit 91e9537 into ServiceStackV3:master Jan 9, 2013
@mythz
Copy link
Copy Markdown
Contributor

mythz commented Jan 9, 2013

Brilliant, thx!

@brgrz
Copy link
Copy Markdown

brgrz commented Apr 25, 2013

Why does he register this auth provider against MvcApplication.Store? What is MvcApplication.Store in his case? Why does the constructor want IDocumentStore instance, when most registratitions are done with IDocumentSession? I have EmbeddableDocumentStore registered as IDocumentSession:

Autofac:
builder.Register(c => ravenStore.OpenSession());

?

@sgraphics
Copy link
Copy Markdown
Contributor Author

Store is the DocumentStore object that is created once per application (http://ravendb.net/kb/3/using-ravendb-in-an-asp-net-mvc-website). Are you running into problems?

@brgrz
Copy link
Copy Markdown

brgrz commented Apr 26, 2013

As described in the article you are referring to, we should use IDocumentSession interface in controllers and as such we register the IDocumentSession with IoC container not the IDocumentStore. Like this:

        // RavenDB registration
        IDocumentStore ravenStore = new EmbeddableDocumentStore
        {
            DataDirectory = "App_Data",
            UseEmbeddedHttpServer = runHttpServer
        }.RegisterListener(new AuditableDocumentListener(GetCurrentUser)).Initialize();

        IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), ravenStore);
        builder.Register<IDocumentSession>(c => ravenStore.OpenSession());

So the contructor in RavenUserAuthRepository should accept IDocumentSession or at least two constructors should exists, one with IDocumentStore and another with IDocumentSession.

I also don't like how you are opening the session yourself in the repository. If you'd use IDocumentSession provided by the container the container would manage opening, closing and initializing the session.

Will you change it or should I implement my own solution?

@brgrz
Copy link
Copy Markdown

brgrz commented Apr 26, 2013

The point is, having MvcApplication.Store as a global object doesn't make much sense, especially when you have a DI container serving the registered service implementations..

@sgraphics
Copy link
Copy Markdown
Contributor Author

Good point, the example is pretty lousy as it uses ioc for the provider but not for raven session. As for opening a session inside it... I don't think it matters too much as no db objects travel in or out f the provider. but I agree that it would make sense to use session directly if its already managed by something.

Feel free to make changes as I wont have time for few weeks at this point :\

@brgrz
Copy link
Copy Markdown

brgrz commented Apr 26, 2013

I found out an alternative to access the document store from the registered Session. Hopefully this will work (haven't tried it out yet):

        var ravenStore = ((IDocumentSession)container.Resolve<IDocumentSession>()).Advanced.DocumentStore;
        container.Register<IUserAuthRepository>(new RavenUserAuthRepository(ravenStore));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants