Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:36:21+00:00 2026-06-05T11:36:21+00:00

This is my Global.asax.cs public void RegisterContainersUsingAutofac() { //http://elegantcode.com/2009/01/07/ioc-libraries-compared/ //http://www.codeproject.com/Articles/25380/Dependency-Injection-with-Autofac //https://code.google.com/p/autofac/ //http://api.autofac.org/ var builder

  • 0

This is my Global.asax.cs

public void RegisterContainersUsingAutofac()
    {
        //http://elegantcode.com/2009/01/07/ioc-libraries-compared/
        //http://www.codeproject.com/Articles/25380/Dependency-Injection-with-Autofac
        //https://code.google.com/p/autofac/
        //http://api.autofac.org/
        var builder = new ContainerBuilder();
        builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
        builder.RegisterModelBinderProvider();
        //builder.RegisterType<AuthenticationService>().As<IAuthenticationService>();
        builder.RegisterControllers(typeof(MvcApplication).Assembly);

        //builder.RegisterAssemblyTypes(typeof(SecurityService).Assembly).
        //      Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerHttpRequest();
        builder.RegisterType(typeof(UnitOfWork)).As(typeof(IUnitOfWork)).InstancePerLifetimeScope()
            .OnRelease(x =>{((IUnitOfWork)x).Commit();});

        builder.RegisterAssemblyTypes(typeof(UserRepository).Assembly).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces();
        builder.RegisterAssemblyTypes(typeof(SecurityService).Assembly).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces();

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

And i’m having the following error:
No constructors on type ‘AppBase.Service.UserService’ can be found with ‘Public binding flags’.

I registered my implemented interfaces of repositories and services, but where did i go wrong? It breaks at the following.

This is my userService

 public interface IUserService
{
    int Login(string userNameOrEmail, string password, out int errorcode, out int timeout);
    bool Register(string userName, string password, string email, string country, string language, out int errorCode);

    bool Register(User user, out int errorCode);
    bool ResetPassword(string username, string email, string oldPassword, string newPassword, out int errorCode);

    void DeleteUser(string userName);
}
public class UserService : IUserService
{
      private readonly IUserRepository userRepository;
     private UserService(IUserRepository _userRepository)
    {
        userRepository = _userRepository;

    }
    //other methods ...

}

This is my error:

 [DependencyResolutionException: No constructors on type 'AppBase.Service.UserService' can be found with 'Public binding flags'.]
 Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +261
 Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +91
 Autofac.Core.Resolving.InstanceLookup.Execute() +135
 Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +434
 Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +61
 Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +68
 Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +201
             Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +499
 Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +91
 Autofac.Core.Resolving.InstanceLookup.Execute() +135
 Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +434
 Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +52
 Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +115
 Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +300
 Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +103
 Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) +218
 Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable`1 parameters) +64
 Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType) +43
 Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(Type serviceType) +49
 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +51

 [InvalidOperationException: An error occurred when trying to create a controller of type 'AppBase.Web.Controllers.AccountController'. Make sure that the controller has a parameterless public constructor.]
 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182
 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +232
 System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49
 System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
 System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
  System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124
 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8968180
 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:36:23+00:00Added an answer on June 5, 2026 at 11:36 am

    I’m not sure why UserService has a private constructor. Is there a reason for this?

    By defining a constructor, the default constructor public UserService() is no longer generated.

    Autofac will only inject into public constructors, of which you now have none. It should work if you change it to public.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've setup the ReisterGlobalFilters method like this in my Global.asax: public static void RegisterGlobalFilters(GlobalFilterCollection
I have this code in Global.asax.cs: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.MapRoute(
This is my Global.asax.cs file: public class MvcApplication : System.Web.HttpApplication { public static void
Hi I have this piece of code in global.asax public void Application_PreRequestHandlerExecute(object sender, EventArgs
This is my RegisterRoutes method in global.asax: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo});
I try in Global.asax protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); this.Error += new
I have defined a series of Routes in Global.asax.cs: public static void RegisterRoutes(RouteCollection routes)
Given this Global.asax.cs: using System; using System.Web; namespace Foo.Web { public class Global :
I have registered a component like this in my Global.asax.cs: ContainerBuilder builder = new
I have this code public static Boolean freq[] = new Boolean[Global.iParameter[2]]; freq[Global.iParameter[2]] = false;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.