Hi
I having some problems implementing IOC using windsor. I have several different implementations of a data access class and i want to use windsor to be able to specify which data access class to use when using a business object. See the code below
public interface IPersistable
{
bool Save();
bool Delete();
}
public class Address
{
public Address()
{
}
public Address(IPersistable Factory)
{
this.DataAccess = Factory;
}
private IPersistable _DataAccess;
public IPersistable DataAccess
{
get { return _DataAccess; }
set { _DataAccess = value; }
}
}
public class AddressFactoryUsingSQL : IPersistable
{
public bool Save()
{
throw new NotImplementedException();
}
public bool Delete()
{
throw new NotImplementedException();
}
}
public class AddressFactoryUsingWebService : IPersistable
{
public bool Save()
{
throw new NotImplementedException();
}
public bool Delete()
{
throw new NotImplementedException();
}
}
public class AddressFactoryUsingRepository : IPersistable
{
public bool Save()
{
throw new NotImplementedException();
}
public bool Delete()
{
throw new NotImplementedException();
}
}
Add when the class is consumed im using the following:
Address addr = new Address(new AddressFactoryUsingSQL);
I want to be able to use Windsor so i can write something similar to:
IWindsorContainer _Container= new WindsorContainer();
_Container.Register(Castle.MicroKernel.Registration.Component.For<IPersistable>()); //this would retrieve the IPersistable class i want to use for the Address business object
IPersistable addrF = _Container.Resolve<IPersistable>();
Address addr = new Address(addrF);
how do i achieve this? I get the error message," Type IPersistable is abstract. As such, it is not possible to instansiate it as implementation of IPersistable service"
I want to be able to change the data access method without having to change all of my code. Also, how can i use web.config to this?
Al