简体   繁体   中英

MVC Controller initializer is being called many times

The problem:

When I'm loading my application is trying to initialize the main controller many times and I would like to know why... that's making me crazy, If one of us had a similar error and want to give me trips about what I have to check, I'll be agreed!!.

MVC3 C# Using Unity as IoC

Controller:

    public ValorationController(IServiceProxy serviceProxy, 
                                IHvmService hvmService, 
                                IFamilyGroupService familyGroupService, 
                                IClientService clientService,
                                IUserService userService,
                                IOfficeService delegationService,
                                ISocietyService societyService,
                                IFamilyService familyService,
                                IArticleService articleService,
                                IArticleFinishedService articleFinishedService,
                                IOrderService orderService)
        : base(serviceProxy)
    {
        FamilyService = familyService;
        ArticleService = articleService;
        HvmService = hvmService;
        FamilyGroupService = familyGroupService;
        ClientService = clientService;
        UserService = userService;
        DelegationService = delegationService;
        SocietyService = societyService;
        ArticleFinishedService = articleFinishedService;
        OrderService = orderService;
    } 

Your controller will be initialized on every request that involves it.

This is normal and how IIS works.

Also good to know that every Unity Resolve will create by default a new instance . If you do not want that, you should provide a LifeTimeManager

Read Microsoft's articles about Understanding Lifetime Managers and Using Lifetime Managers .

Maybe you want to use something like this:

// Register a default (un-named) type mapping with a singleton lifetime 
myContainer.RegisterType<IMyObject, MySingletonObject>(new ContainerControlledLifetimeManager());
// Following code will return a singleton instance of MySingletonObject// Container will take over lifetime management of the object
myContainer.Resolve<IMyObject>();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM