Unity MVC5

Mar 12, 2014 at 6:40 PM
Hi guys,
I not sure if this is good place to ask this question or not. If not please direct me to right place.

I'm using Repository pattern and using
container.RegisterTypes(
    AllClasses.FromLoadedAssemblies().Where(x =>
         x.Namespace != null && (x.Namespace.Contains("TM.Service") ||
          x.Namespace.Contains("TM.Repository"))
    ),
    WithMappings.FromMatchingInterface,
    WithName.Default,
    WithLifetime.PerResolve
 );
every thing works at first, but after changing cshtml file or even a js file at run time, (Start debugging or Start without debugging) I get "The type IUserService does not have an accessible constructor." error!
That's driving me crazy, because that was working just a second ago!
When this error occurs, restarting webapp doesn't work or even building project. The only way to get webapp running again is to Rebuild Solution.

btw, my repositories and services are in separate projects.
Mar 14, 2014 at 6:00 AM
This post looks to be similar to what you are seeing where AppDomain.CurrentDomain.GetAssemblies() is not returning all assemblies after bouncing the AppDomain: http://stackoverflow.com/questions/3552223/asp-net-appdomain-currentdomain-getassemblies-assemblies-missing-after-app

You could try changing the call AllClasses.FromLoadedAssemblies() to AllClasses.FromAssembliesInBasePath() so that assemblies on disk are searched instead of loaded assemblies.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Mar 14, 2014 at 2:37 PM
Another way to get all of thls in the bin folder is using this line of code
System.Web.Compilation.BuildManager.GetReferencedAssemblies().OfType<Assembly>();
            
Apr 30, 2014 at 2:52 PM
Edited Apr 30, 2014 at 2:52 PM
Thanks guys, and sorry for late reply.

thanks to @randylevy, I managed to fix this issue with initializing a dummy class from services assembly in the Application_Start.
the working code looks likes
 protected void Application_Start()
        {           
            //For IoC Sake!
            var dummyRepository = new DummyRepository();
            var dummyService = new DummyService();

            ...
        }