Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2007
    Posts
    640

    Question Autofac question for BuzzMMO.Web

    Today I got the BuzzMMO.Web project working with Autofac. I'm not sure if I've done everything right but during my (limited) testing things seem to be working.

    My question is do I need to do something like this

    Code:
      	builder.RegisterControllers(typeof (MvcApplication).Assembly).InstancePerRequest();
    	builder.RegisterApiControllers(typeof (MvcApplication).Assembly).InstancePerRequest();
    	builder.RegisterAssemblyTypes(typeof (MMODatabaseContext).Assembly).InstancePerRequest();
    Or can I leave off the InstancePerRequest? It seems to work both ways. I'm tempted to also add/chagne InstancePerRequest to InstancePerLifetimeScope but I'm not sure...

  2. #2
    Join Date
    Mar 2004
    Location
    UK
    Posts
    85
    I think if you set your controllers to InstancePerLifetimeScope and they're called more than once (partial views) it will error. InstancePerRequest though should create a new instance in that situation and not error, I think.

  3. #3
    Join Date
    Jan 2007
    Posts
    640
    I thought I had the IoC container working... but it was just chrome caching the Auth cookie. Now when I try to log in I can't because the HttpContext returns null. Here's the full IoC setup method. Any pointers would be helpful.

    Code:
    private void RegisterIOC()
            {
                var builder = new ContainerBuilder();
                builder.RegisterControllers(typeof (MvcApplication).Assembly).InstancePerRequest();
                builder.RegisterApiControllers(typeof (MvcApplication).Assembly).InstancePerRequest();
                builder.RegisterAssemblyTypes(typeof(MMODatabaseContext).Assembly).InstancePerRequest();
                var container = builder.Build();
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
                GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            }
    Last edited by VelariaKnight; 06-13-2014 at 12:50 PM.

  4. #4
    Join Date
    Mar 2004
    Location
    UK
    Posts
    85
    Could you paste the code that is attempting to use the HttpContext?

  5. #5
    Join Date
    Jan 2007
    Posts
    640
    Hi ScariestLlama

    I want to thank you for the help. After I had posted my Auth.cs class I went back to Bitbucket and retrieved a known working copy of the file. I found the missing line of code:

    Code:
    HttpContext.Current.Response.Cookies.Add(authCookie);
    The above line of code was missing form my Auth.cs class... which meant the cookie int eh browser was not being set.

    Thanks again for taking the time to help me.
    Last edited by VelariaKnight; 06-13-2014 at 09:48 PM.

  6. #6
    Join Date
    Sep 2014
    Posts
    1

    Mohsin

    I'm not sure if I've done everything right but during my (limited) testing things seem to be working.
    Mohsin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •