Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity 3 Configuration By Convention not finding Types in Web Project

I am trying to get this convention configuration working but I am having a problem in my ASP.NET MVC5 Project..

I have added the following in my Application_Start method and hooked it up to DependencyResolver

 public static IUnityContainer CreateContainer()
    {
        IUnityContainer container = new UnityContainer();

        container.RegisterTypes(

            AllClasses.FromAssembliesInBasePath(),

            WithMappings.FromAllInterfaces,

            WithName.Default,

            WithLifetime.ContainerControlled);

        return container;
    }

But it fails to register any types, on closer inspection, when I see whats in AllClasses.FromAssembliesInBasePath() it always runs null or empty.

Am I doing something wrong? is there a better place I should put this?

Thanks. Ste.

like image 299
Steoates Avatar asked Mar 21 '23 00:03

Steoates


1 Answers

The reason might be that the domain base path is not what you thought.

Please try this see if it registers anything:

  container.RegisterTypes(

        AllClasses.FromAssemblies(Assembly.GetExecutingAssembly()),

        WithMappings.FromAllInterfaces,

        WithName.Default,

        WithLifetime.ContainerControlled);
like image 64
Stephen Zeng Avatar answered Mar 22 '23 23:03

Stephen Zeng