MVC 5 app using Autofac MVC 4 Integration package?

5,218 views
Skip to first unread message

Javier Darsie

unread,
Jul 19, 2013, 2:07:25 PM7/19/13
to aut...@googlegroups.com
Hello there,

Quick questions. Can I use the ASP.NET MVC 4 Integration nuget package to build a ASP.NET MVC 5 app? Did anybody test it? Any known issue?

Thanks,
Javier

Travis Illig

unread,
Jul 30, 2013, 12:39:24 PM7/30/13
to aut...@googlegroups.com
I don't think anyone has specifically tested it, but I don't know of any gotchas. Maybe you could try it out and let us know? :)

Javier Darsie

unread,
Aug 3, 2013, 1:30:34 PM8/3/13
to aut...@googlegroups.com
I am using the basic features and so far so good. Will report any problem. Thanks.

jb...@terryberry.com

unread,
Aug 28, 2013, 4:48:32 PM8/28/13
to aut...@googlegroups.com

This worked for me when I was using -beta2 of the Mvc 5 nuget package.

However upgrading to -rc1 causes this error:

[HttpException (0x80004005): Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9913001
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

jb...@terryberry.com

unread,
Aug 28, 2013, 8:08:28 PM8/28/13
to aut...@googlegroups.com, jb...@terryberry.com

I see this was issue was already fixed: https://code.google.com/p/autofac/issues/detail?id=453

Alex Meyer-Gleaves

unread,
Aug 30, 2013, 9:49:06 PM8/30/13
to aut...@googlegroups.com
I am going to work on official MVC 5 and Web API 2 packages this week. I'll keep you posted. :)



--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autofac+u...@googlegroups.com.
To post to this group, send email to aut...@googlegroups.com.
Visit this group at http://groups.google.com/group/autofac.
For more options, visit https://groups.google.com/groups/opt_out.

Alex Meyer-Gleaves

unread,
Sep 3, 2013, 12:11:14 AM9/3/13
to aut...@googlegroups.com
I have pushed prerelease packages for MVC 5 RC1 and Web API 5 RC1 to NuGet.



There was plenty of SecurityCritical attributes required along with the .NET 4.5 upgrade to please let me know if you find any issues.

Javier Darsie

unread,
Sep 5, 2013, 6:49:17 PM9/5/13
to aut...@googlegroups.com
Thanks Alex,

Found this error right after I upgrade to Autofac.Mvc5 rc1 https://gist.github.com/jdarsie/6457273#file-autofac-mvc5-3-0-0-rc1

Alex Meyer-Gleaves

unread,
Sep 6, 2013, 7:09:17 AM9/6/13
to aut...@googlegroups.com
Is that using the latest RC1 packages for MVC or the Beta?

Javier Darsie

unread,
Sep 6, 2013, 9:15:25 AM9/6/13
to aut...@googlegroups.com
That is using Microsoft.AspNet.Mvc 5.0.0-rc1-130712.

Below I have pasted my packages.config in case you need more info.

Thanks,

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
  <package id="Autofac" version="3.1.1" targetFramework="net45" />
  <package id="Autofac.Mvc4" version="3.1.0" targetFramework="net45" />
  <package id="EntityFramework" version="5.0.0" targetFramework="net45" />
  <package id="jQuery" version="2.0.3" targetFramework="net45" />
  <package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
  <package id="Knockout.Mapping" version="2.4.0" targetFramework="net45" />
  <package id="Knockout.Validation" version="1.0.1" targetFramework="net45" />
  <package id="knockoutjs" version="2.3.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Mvc" version="5.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.Data" version="2.0.20710.0" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.3" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.7" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Ajax" version="3.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0-rc1-130712" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.13" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Modernizr" version="2.6.2" targetFramework="net45" />
  <package id="Moment.js" version="2.1.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
  <package id="RestSharp" version="104.1" targetFramework="net45" />
  <package id="Twitter.Bootstrap" version="2.3.2" targetFramework="net45" />
  <package id="WebGrease" version="1.5.2" targetFramework="net45" />
  <package id="WebMatrix.Data" version="2.0.30506.0" targetFramework="net45" />
</packages>

alexande...@gmail.com

unread,
Oct 5, 2013, 11:39:23 AM10/5/13
to aut...@googlegroups.com
To those still struggling with this problem, this is just because the AutofacDependencyResolver implements IDependencyResolver from the System.Web.Mvc library version 4.

If you copy the source code of AutofacDependencyResolver to your project and make it implement the IDependencyResolver of MVC 5, it works. You don't need to change the actual implementation.

alex.mey...@gmail.com

unread,
Oct 5, 2013, 10:42:30 PM10/5/13
to aut...@googlegroups.com
Have you tried the MVC 5 integration prerelease package?


This is compiled against the 5 RC1 version.



From: alexande...@gmail.com<alexande...@gmail.com>
To: <aut...@googlegroups.com>
Sent: Sunday, October 6, 2013
Subject: Re: MVC 5 app using Autofac MVC 4 Integration package?

tranda...@gmail.com

unread,
Oct 15, 2013, 4:59:32 AM10/15/13
to aut...@googlegroups.com
On Sunday, October 6, 2013 9:42:30 AM UTC+7, Alex Meyer-Gleaves wrote:
> Have you tried the MVC 5 integration prerelease package?
>
>
> https://www.nuget.org/packages/Autofac.Mvc5
>
>
> This is compiled against the 5 RC1 version.
>
I used Autofac and Autofac.Mvc 5 and registered type
"builder.RegisterType(UserService).As(IUserService).InstancePerHttpRequest();"
My UserService have 2 constructor but Autofac alway run default constructor
(it not happened previous version). So how to call constructor parameter?

Below I have my packages.config
<package id="Autofac" version="3.1.1" targetFramework="net451" />
<package id="Autofac.Mvc5" version="3.0.0-rc1" targetFramework="net451" />

Alex Meyer-Gleaves

unread,
Oct 16, 2013, 8:32:14 AM10/16/13
to aut...@googlegroups.com, tranda...@gmail.com
If your services are registered in the container, then it sounds like the dependency resolver is not being invoked.

Make sure you have set the dependency resolver instance:

var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

For more information see the existing MVC documentation. This should still be relevant for MVC 5.


Cheers,

Alex.

ma...@centiva.si

unread,
Oct 16, 2013, 10:45:08 AM10/16/13
to aut...@googlegroups.com, tranda...@gmail.com
On Wednesday, October 16, 2013 2:32:14 PM UTC+2, Alex Meyer-Gleaves wrote:
> If your services are registered in the container, then it sounds like the dependency resolver is not being invoked.
>
>
> Make sure you have set the dependency resolver instance:
>
>
>
>
FWIW I can confirm that those two packages work with MVC 5 and Web API 2 while the previous ones (Autofac MVC4 integration) did not.

alex.mey...@gmail.com

unread,
Oct 18, 2013, 11:23:50 AM10/18/13
to aut...@googlegroups.com
Thanks for the feedback Marko.

-----Original Message-----

From: ma...@centiva.si<ma...@centiva.si>
To: <aut...@googlegroups.com>
cc: <tranda...@gmail.com>
Sent: Thursday, October 17, 2013
Subject: Re: MVC 5 app using Autofac MVC 4 Integration package?


tza...@gmail.com

unread,
Oct 31, 2013, 12:33:02 AM10/31/13
to aut...@googlegroups.com
Hi,

I noticed the MVC5 version is marked as Stable, however the WebApi5 is Pre-Release... Is there going to be Stable for each now that RTM is out?

Thanks,
Troy

Alex Meyer-Gleaves

unread,
Oct 31, 2013, 3:57:22 AM10/31/13
to aut...@googlegroups.com, tza...@gmail.com
The WebApi package was released as Autofac.WebApi2. Apparently the official version is Web API 2, even though the packages are version 5.0.0. Unfortunately I cannot delete a package from NuGet so it will have to stay there. Maybe one day we will actually reach Web API 5. That will will probably be version 8.0.0 (*eyes roll*). :)
Reply all
Reply to author
Forward
0 new messages