how to regester generic class?

Nov 2, 2011 at 9:07 AM

my code like is :


namespace PianoDAL
{
    public interface IDataMapper<T>
    {
        bool Create(T item);
        bool Update(T item);
        bool Delete(T item);

        IList<T> GetAll();
        T GetByKey(object key);
    }
}

namespace PianoDAL.BaseInfo
{
    public class PianoAreaDal : IDataMapper<PianoArea>
    {
        public bool Create(PianoArea newPianoArea)
        {
            pianoEntities pe = new pianoEntities();
            pe.PianoAreas.Add(newPianoArea);
            return pe.SaveChanges() > 0 ? true : false;
        }
……
}

namespace PianoBusiness.BaseInfo.Impl
{
    public class PianoAreaService : IPianoAreaService
    {
        private IDataMapper<PianoArea> _pianoAreaDal;

        public PianoAreaService(IDataMapper<PianoArea> pianoAreaDal)
        {
            _pianoAreaDal = pianoAreaDal;
        }

        public bool AddPianoArea(PianoArea newPianoArea)
        {
            return _pianoAreaDal.Create(newPianoArea);
        }
……
}
<alias alias="IDataMapper" type="PianoDal.IDataMapper`1,PianoDAL"/>
    <alias alias="PianoAreaDal" type="PianoDAL.BaseInfo.PianoAreaDal,PianoDAL"/>

    <alias alias="IPianoAreaService" type="PianoBusiness.BaseInfo.IPianoAreaService,PianoBusiness"/>
    <alias alias="PianoAreaService" type="PianoBusiness.BaseInfo.Impl.PianoAreaService,PianoBusiness"/>
    
    <container name="pianoContainer">
      <register type ="IDataMapper" mapTo="PianoAreaDal" name="pianoAreaDal"/>
      
      <register type="IPianoAreaService" mapTo="PianoAreaService" name="pianoAreaService">
        <constructor>
          <param name="pianoAreaDal">
            <dependency name="pianoAreaDal"></dependency>
          </param>
        </constructor>
      </register>
    </container>
when run unit test throw exception:
System.InvalidOperationException: The type name or alias IDataMapper could not be resolved. Please check your configuration file and verify this type name.

how to do?
tks!

Nov 3, 2011 at 5:53 AM
Edited Nov 3, 2011 at 5:55 AM

It looks like you have a typo on the namespace case for IDataMapper.  

The config above has:

<alias alias="IDataMapper" type="PianoDal.IDataMapper`1,PianoDAL"/>

It should be:

<alias alias="IDataMapper" type="PianoDAL.IDataMapper`1,PianoDAL"/>

 

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Nov 3, 2011 at 6:07 AM

oh stupid

thank you!