Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserStore and RoleStore to depend on ISessionFactory / ICurrentSessionContext instead of ISession? #25

Open
hazzik opened this issue Feb 16, 2015 · 13 comments

Comments

@hazzik
Copy link
Member

hazzik commented Feb 16, 2015

No description provided.

@hazzik hazzik changed the title UserStore and RoleStore to depend on ISessionFactory / ICurrentSessionContext ? UserStore and RoleStore to depend on ISessionFactory / ICurrentSessionContext instead of ISession? Feb 16, 2015
@hazzik
Copy link
Member Author

hazzik commented Feb 16, 2015

/cc @lnu @DennisFrostlander @milesibastos

@ghost
Copy link

ghost commented Feb 16, 2015

Just my 2c - I would prefer "in addition to" ISession to "instead of". With the current variety of IoC containers with their own 'per-request' lifetime scopes, async owin frameworks etc, I often find it easier to open session myself and rely on IoC's capabilities for lifetime management than use Nhibernate's contexts.

@lnu
Copy link
Member

lnu commented Feb 17, 2015

I also prefer to manage the session myself. I'd also rather stick to the EF implementation as much as possible. But if the option of could be added while keeping the current implementation, it's ok for me.

@ewhitmore
Copy link

Has anyone gotten this to work with Unity IoC container?

@lnu
Copy link
Member

lnu commented Apr 9, 2015

Something like that:

            // session used by asp.net identity
            container.RegisterType<ISession>(new PerRequestLifetimeManager(), new InjectionFactory(c =>
            {
                return NHibernateSessionFactoryUser.SessionFactory.OpenSession();
            }));

            container.RegisterType<IRoleStore<EcdtRole>, RoleStore<EcdtRole>>(new PerRequestLifetimeManager(),
                new InjectionConstructor(new ResolvedParameter<ISession>()));
            container.RegisterType<IUserStore<EcdtUser>, UserStore<EcdtUser>>(new PerRequestLifetimeManager(),
                new InjectionConstructor(new ResolvedParameter<ISession>()));
            container.RegisterType<IAuthenticationManager>(new PerRequestLifetimeManager(), new InjectionFactory(c =>
            {
                return System.Web.HttpContext.Current.GetOwinContext().Authentication;
            }));

            container.RegisterType<EcdtUserManager>(new PerRequestLifetimeManager());
            container.RegisterType<EcdtRoleManager>(new PerRequestLifetimeManager());
            container.RegisterType<EcdtSignInManager>(new PerRequestLifetimeManager());

We first register an injection factory to resolve ISession. Then we configure injection for IRoleStore and IUserStore and for our custom Managers. Seems ok for you?

@ewhitmore
Copy link

@lnu, thanks for your input. I am still unable to get it to work. Do you have a extremely stripped down sample project on github which uses ASP.NET MVC, NHibernate.AspNet.Identity and Unity IoC that i can pull from?

Basically, VS can't resolve EcdtRole, EcdtUser, EcdtUserManager. Where did you get these models from?

@lnu
Copy link
Member

lnu commented Apr 9, 2015

is this enough https://github.com/lnu/NHibernateIdentity?
Not up to date but it used to work

ps: everything related to Ecdt is custom implementation for one of my project

On Thu, Apr 9, 2015 at 3:11 PM, Eric Whitmore [email protected]
wrote:

@lnu https://github.com/lnu, thanks for your input. I am still unable
to get it to work. Do you have a extremely stripped down sample project on
github which uses ASP.NET MVC, NHibernate.AspNet.Identity and Unity IoC
that i can pull from?


Reply to this email directly or view it on GitHub
#25 (comment)
.

@ewhitmore
Copy link

I will check it out. Thanks!

@lnu
Copy link
Member

lnu commented Apr 9, 2015

I've updated the project

@ewhitmore
Copy link

Does this method work with asp.net identity managers? I enabled role manager in the web.config () but when i try to actually create a role (roles.create("Admin");) i get the following error:

Additional information: Unable to connect to SQL Server database.

Am i missing something?

@lnu
Copy link
Member

lnu commented May 4, 2015

What do you mean by ASP.NET identity managers?

@ewhitmore
Copy link

https://msdn.microsoft.com/en-us/library/system.web.security.roles.createrole(v=vs.110).aspx

for example. if i try to do something like

public class testController : ApiController
{
public void Get()
{
Roles.CreateRole("test");
}
}

I get the error: Additional information: Unable to connect to SQL Server database.

@lnu
Copy link
Member

lnu commented May 5, 2015

This code works with the old membership system and forms authentication. I don't think it still works with Asp.Net Identity.

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

No branches or pull requests

3 participants