how to regester generic class?

Nov 2, 2011 at 8: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();
            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">
          <param name="pianoAreaDal">
            <dependency name="pianoAreaDal"></dependency>
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?

Nov 3, 2011 at 4:53 AM
Edited Nov 3, 2011 at 4: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

Nov 3, 2011 at 5:07 AM

oh stupid

thank you!