Hello,
It's the first time I use RhinoTools and I have some trouble
I have this error
failed: No component for supporting the service
Rhino.Commons.IRepository`1[[Planning.Core.DomainModel.Employee,
Planning.Core.DomainModel, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] was found
Castle.MicroKernel.ComponentNotFoundException: No component for
supporting the service Rhino.Commons.IRepository`1
[[Planning.Core.DomainModel.Employee, Planning.Core.DomainModel,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] was found
My code
I have an Employee class
public class Employee : DomainFoundation
{
}
public abstract class DomainFoundation
{
public virtual int Id { get; set; }
public virtual bool IsEqual(DomainFoundation domainFoundation)
{
if (domainFoundation == null)
return false;
return (Id == domainFoundation.Id);
}
public override int GetHashCode()
{
return this.Id.GetHashCode();
}
public static bool operator ==(DomainFoundation x,
DomainFoundation y)
{
if (ReferenceEquals(x, y))
return true;
if (((object)x == null) || ((object)y == null))
return false;
return (x.Id == y.Id);
}
public static bool operator !=(DomainFoundation x,
DomainFoundation y)
{
return !(x == y);
}
public override bool Equals(object obj)
{
if (obj == null || !(obj is DomainFoundation))
return false;
return (this == (DomainFoundation)obj);
}
}
The mapping
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Planning.Core.DomainModel"
namespace="Planning.Core.DomainModel" default-lazy="true">
<class name="Employee" table="Employee">
<id name="Id" column="Id" type="int" access="field" unsaved-value
="0">
<generator class="identity" />
</id>
</class>
</hibernate-mapping>
I can create the databasez from the mapping
The repository
[Transactional]
public abstract class RepoFoundation<T> : IRepoFoundation<T>
where T : DomainFoundation
{
/// <summary>
/// Gets the object with the specified id.
/// </summary>
/// <param name="id">The id.</param>
/// <returns></returns>
public virtual T Get(int id)
{
return Repository<T>.Get(id);
}
public virtual ICollection<T> GetAll()
{
return Repository<T>.FindAll();
}
public FutureQueryOf<T> GetAll(int firstResult, int
numberOfResults,
string orderBy, string sortOrder)
{
return GetAll(firstResult, numberOfResults, orderBy,
sortOrder, null);
}
public FutureQueryOf<T> GetAll(int firstResult, int
numberOfResults,
string orderBy, string sortOrder, IEnumerable<string>
eagerLoadingFor)
{
NHibernate.Criterion.Order order;
var criteria = CriteriaUtil<T>.GetOrderByCriteriaForGetAll
(sortOrder, orderBy, out order, eagerLoadingFor);
return new FutureQueryOf<T>(criteria, firstResult,
numberOfResults);
}
public IEnumerable<T> GetByCommaSeparatedIds(string
commaSeparatedIds)
{
if (!string.IsNullOrEmpty(commaSeparatedIds))
foreach (var id in commaSeparatedIds.Split(','))
if (id != string.Empty)
yield return Repository<T>.Get(Convert.ToInt32
(id));
}
[Transaction]
public virtual void Remove(T instance)
{
if (!Exists(instance))
throw new StaleObjectStateException("DomainObject",
"The object you are trying to delete has already been removed from the
datastore.");
//ValidationManager.Validate(instance,
PersistanceAction.Delete);
Repository<T>.Delete(instance);
}
[Transaction]
public virtual void Save(T instance)
{
Repository<T>.Save(instance);
}
public virtual bool Exists(int? id)
{
if (id != null && id != 0)
return Repository<T>.Get(id) != null;
throw new InvalidOperationException("The parameter you
passed was invalid.");
}
public virtual bool Exists(T instance)
{
if (instance != null)
return Get(instance.Id) != null;
throw new InvalidOperationException("The parameter you
passed was invalid.");
}
public bool IsUpdate(int id)
{
return Repository<T>.Get(id) != null;
}
public virtual ICollection<T> FindAll(DetachedCriteria
detachedCriteria)
{
return Repository<T>.FindAll(detachedCriteria);
}
public virtual ICollection<T> FindAll()
{
return Repository<T>.FindAll();
}
public virtual T FindFirst(DetachedCriteria detachedCriteria)
{
return Repository<T>.FindFirst(detachedCriteria);
}
}
public interface IEmployeeRepository
{
Employee GetEmployee(Guid id);
IList<Employee> GetListEmployee();
void SaveOrUpdateEmployee(Employee employee);
}
public class EmployeeRepository : RepoFoundation<Employee>
{
public virtual Employee GetEmployee(int id)
{
return Get(id);
}
public IList<Employee> GetListEmployee()
{
return FindAll().ToList<Employee>();
}
public void SaveOrUpdateEmployee(Employee employee)
{
base.Save(employee);
}
}
I have the problem when I do this :
[TestFixture]
public class RepositoryEmployeeTests
{
[Test]
public void Employee_CanGetFromId()
{
HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize
();
WindsorContainer container = new WindsorContainer();
container.AddComponent<IUnitOfWorkFactory,
NHibernateUnitOfWorkFactory>();
IoC.Initialize(container);
EmployeeRepository employeeRepo = new EmployeeRepository
();
employeeRepo.FindAll();
}
}
Could you help me ?
Thanks,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---