I have 2 classes for data handling:
public class SqlDataProvider<T> : IDataProvider<T> where T : IEntity
public class MongoDataProvider<T> : IDataProvider<T> where T : IEntity
and I have a lots of model like these:
public class Account : ISqlDbEntity
public class Log : IMongoDbEntity
with those interfaces:
public interface IMongoDbEntity : IEntity
public interface ISqlDbEntity : IEntity
How should I register or is that possible to register the Windsor container as generics but the MondoDbEntity be used with MongoDbProvider, and the MsSQl models be used with the SqlDataProvider.
container.Register(Component.For(typeof(IDataProvider<>))
.ImplementedBy(typeof(SqlDataProvider<>))
.LifestylePerWebRequest()); //I want this work only with ISqlEntity
container.Register(Component.For(typeof(IDataProvider<>))
.ImplementedBy(typeof(MongoDataProvider<>))
.LifestylePerWebRequest()); //I want this work only with IMongoDbEntity
I have tried these, but was not working:
container.Register(Component.For(typeof(IDataProvider<ISqlDbEntity>))
.ImplementedBy(typeof(SqlDataProvider<>))
.LifestylePerWebRequest());
container.Register(Component.For(typeof(IDataProvider<IMongoDbEntity>))
.ImplementedBy(typeof(MongoDataProvider<>))
.DependsOn(Dependency.OnAppSettingsValue("databaseName", "MongoDatabaseName"))
.LifestylePerWebRequest());
Thx in advance!
This factory method works perfect!