Avatar of foxhardx
foxhardx
Flag for Peru asked on

My WeApp works fine but then 10 or 20 minutes later it fall. Because Microsoft Unity (v3.0) don't have a registered class to match with some interface..

The problem happens when the web is deployed in the server. I don't know maybe the session issue or something like that...

I'm using Unity 3.0 as IOC and Asp.net Mvc5....In my local pc all works fine...when I deploy the solution in a server with IIS7. All works fine, but 10 or 20 minutes later unity don't recognize the matches types... If I stop the server and start again the problems happens again.

--------------------------------------------------------------------------------------------------------------------------------------------
I'm using the unity controller factory:

public class UnityControllerFactory : IControllerFactory
    {
        private IUnityContainer _container;
        private IControllerFactory _innerFactory;

        public UnityControllerFactory(IUnityContainer container)
            : this(container, new DefaultControllerFactory())
        {
        }

        public IController CreateController(RequestContext requestContext, string controllerName)
        {
            try
            {
                return _container.Resolve<IController>(controllerName);
            }
            catch (Exception ex)
            {
                return _innerFactory.CreateController(requestContext, controllerName);
            }
        }

        public void ReleaseController(IController controller)
        {
            _container.Teardown(controller);
        }

        public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
        {
            return SessionStateBehavior.Default;
        }

       
        protected UnityControllerFactory(IUnityContainer container, IControllerFactory innerFactory)
        {
            _container = container;
            _innerFactory = innerFactory;
        }
--------------------------------------------------------------------------------------------------------------------------------------------

This is my UnityConfig

public static void RegisterComponents()
{
    var container = new UnityContainer();
    AppInjections.Register(container);
    DependencyResolver.SetResolver(new UnityDependencyResolver(container));
    var factory = new UnityControllerFactory(container);
    ControllerBuilder.Current.SetControllerFactory(factory);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This is my controller:

public class MyController : Controller
{
        private GeneratorAlpha _generator;
        private FinderBeta _finder;

        public MyController (GeneratorAlpha generator, FinderBeta finder)
        {
            _generate = generator;
            _finder = finder;
        }

        public ActionResult Index()
        {
            return View();
        }
}
Microsoft IIS Web ServerASP.NET

Avatar of undefined
Last Comment
foxhardx

8/22/2022 - Mon
Bob Learned

20 minutes is the default time out for session, so is it 10 minutes or 20 minutes.  

Are you using any global filters to handle session timeout?
Are you getting an exception, with full stack trace?
foxhardx

ASKER
Hi Bob,

I think the problem is caused because I have load unity configuration in global.asax. Then, when the web is recycled, that section does not load anymore. I guess I have move this line: "UnityConfig.RegisterComponents();" to another event what load in each request. What do you think?

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            UnityConfig.RegisterComponents(); // <-------------------------------- Unity Registration
        }
    }
Bob Learned

If this is happening when the session ends, are you looking to handle that gracefully, like redirect to a "session end" page?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
foxhardx

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
foxhardx

ASKER
This solution works for me.