Is there any way to solve this problem with Unity 3 ???
I did everything possible to get around this error message, but I canβt solve it ... Iβve been trying to solve it for 2 days, and already did everything that I saw in the search for searches.
I almost give up and try another DI solution. Please any help would be ok ...
My configuration file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" /> </configSections> <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <assembly name="Biblioteca" /> <assembly name="Biblioteca.Contracts" /> <assembly name="Biblioteca.Business" /> <namespace name="Biblioteca" /> <namespace name="Biblioteca.Contracts" /> <namespace name="Biblioteca.Business" /> <container> <register type="Biblioteca.Contracts.IManterCategoriaBO" mapTo="Biblioteca.Business.ManterCategoriaBO" /> </container> </unity> </configuration>
My interface:
using Biblioteca.Transport; using System.Linq; namespace Biblioteca.Contracts { public interface IManterCategoriaBO { IQueryable<CategoriaDTO> GetAll(); CategoriaDTO GetById(int id); void Insert(CategoriaDTO dto); } }
My specific class:
using Biblioteca.Contracts; using Biblioteca.Transport; using Biblioteca.Data; using System; using System.Linq; namespace Biblioteca.Business { public class ManterCategoriaBO : IManterCategoriaBO { public CategoriaDTO GetById(int id) { CategoriaDTO dto = new CategoriaDTO(); ManterCategoriaDO categoriaDO = new ManterCategoriaDO(); dto = categoriaDO.GetById(1); return dto; } public IQueryable<CategoriaDTO> GetAll() { throw new NotImplementedException(); } public void Insert(CategoriaDTO dto) { throw new NotImplementedException(); } } }
My Global.asax:
using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using Biblioteca.Dependency; namespace Biblioteca {
My Bootstrapper Class:
using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.Configuration; using System.Configuration; using System.Web.Mvc; using Unity.Mvc4; namespace Biblioteca { public static class Bootstrapper { public static IUnityContainer Initialise() { var container = BuildUnityContainer(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); return container; } private static IUnityContainer BuildUnityContainer() { string path = ConfigurationManager.AppSettings["UnityConfigFilePath"].ToString(); var fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = path + "\\Unity.config" }; System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
The static class of the project My Dependency:
using Microsoft.Practices.Unity; namespace Biblioteca.Dependency { public static class Global { public static IUnityContainer Container = null; public static T Resolve<T>() { return Container.Resolve<T>(); } } }
My interface model class file in MVC 4 project. I am using 4.5 framework.
using Biblioteca.Contracts; using Biblioteca.Dependency; namespace Biblioteca.Models { public class LivroModel { public void GetAll() { if (Global.Container != null) { var categoriaBO = Global.Resolve<IManterCategoriaBO>(); categoriaBO.GetById(1); } } } }
I think everything is correct. But I canβt see that this DI works because I only got an error during the matching process, in the line below my Bootstrapper class, the BuildUnityContainer method:
var container = new UnityContainer (). LoadConfiguration (unitySection);
Mistake:
The type name or alias of Biblioteca.Contracts.IManterCategoriaBO may not be resolved. Check the configuration file and check it. type name.
I double-checked all my classes, and for me this is normal. Or is he missing anything?
I need help because I have a short time to take care of this ....
Regards, Marcelo.