I have a problem. I'm implementing a selfhost web api based on Owin and Castle. My interface looks like this:
public interface IFluentStoredProcedureRunner<T> where T : class
{
FluentStoredProcedureRunner<T> WithName(string storedProcedureName);
FluentStoredProcedureRunner<T> WithParameters(List<StoredProcedureParameterDefinition> parameterList = null);
StoredProcedureResult<T> Run();
}
and the implementation looks like this:
public class FluentStoredProcedureRunner<T> : IFluentStoredProcedureRunner<T> where T : class
{
private readonly IStoredProcedureRunner<T> storedProcedureRunner;
private string storedProcedureName = string.Empty;
private List<StoredProcedureParameterDefinition> parameterList = new List<StoredProcedureParameterDefinition>();
public FluentStoredProcedureRunner(IStoredProcedureRunner<T> storedProcedureRunner)
{
this.storedProcedureRunner = storedProcedureRunner;
}
public FluentStoredProcedureRunner<T> WithName(string storedProcedureName)
{
this.storedProcedureName = storedProcedureName;
return this;
}
public FluentStoredProcedureRunner<T> WithParameters(List<StoredProcedureParameterDefinition> parameterList = null)
{
this.parameterList = parameterList;
return this;
}
public StoredProcedureResult<T> Run()
{
return this.storedProcedureRunner.Run(this.storedProcedureName, this.parameterList);
}
}
and the registrations:
public class CoreLibInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For(typeof(IMapper<>))
.ImplementedBy(typeof(MapByFieldNameMapper<>))
.LifestyleTransient());
container.Register(
Component.For(typeof(IStoredProcedureRunner<>))
.ImplementedBy(typeof(StoredProcedureRunner<>))
.LifestyleTransient());
container.Register(
Component.For(typeof(IFluentStoredProcedureRunner<>))
.ImplementedBy(typeof(FluentStoredProcedureRunner<>))
.LifestyleTransient());
container.Register(
Component.For<IAuthenticationService>()
.ImplementedBy<ActiveDirectoryAuthenticationService>()
.LifestyleTransient());
container.Register(
Component.For<IStoredProcedureNameResolverService>()
.ImplementedBy<StoredProcedureNameResolverService>()
.LifestyleTransient());
}
}
Here is the stored procedure runner:
public class StoredProcedureRunner<T> : IStoredProcedureRunner<T> where T : class, new()
{
private const string ConnectionString = "someConnectionString"
private readonly IMapper<T> mapper;
private readonly StoredProcedureResult<T> storedProcedureResult = new StoredProcedureResult<T>();
public StoredProcedureRunner(IMapper<T> mapper)
{
this.mapper = mapper;
}
public StoredProcedureResult<T> Run(
string storedProcedureName,
List<StoredProcedureParameterDefinition> parametersList = null)
{
try
{
using (var conn = new IfxConnection(ConnectionString))
{
conn.Open();
using (var cmd = new IfxCommand())
{
cmd.Connection = conn;
cmd.CommandText = storedProcedureName;
cmd.CommandType = CommandType.StoredProcedure;
if (parametersList != null)
{
foreach (var parameter in parametersList)
{
var parameterToAdd = new IfxParameter
{
ParameterName = parameter.ParameterName,
IfxType = parameter.ParameterType,
Value = parameter.ParamerValue,
Direction = parameter.ParameterDirection
};
cmd.Parameters.Add(parameterToAdd);
}
}
var ifxdr = cmd.ExecuteReader();
this.storedProcedureResult.Rows = this.mapper.Map(ifxdr).ToList();
if (parametersList != null)
{
foreach (var outputParameter in parametersList.Where(pl => pl.ParameterDirection == ParameterDirection.Output))
{
this.storedProcedureResult.OutputParameters.Add(
outputParameter.ParameterName,
cmd.Parameters[outputParameter.ParameterName].Value);
}
}
return this.storedProcedureResult;
}
}
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}
}
This is the interface for it:
public interface IStoredProcedureRunner<T> where T : class
{
StoredProcedureResult<T> Run(
string storedProcedureName,
List<StoredProcedureParameterDefinition> parametersList = null);
}
The problem is that after all of that It is throwing the exception:
ComponentActivator: could not instantiate StoreProcRunLib.DB.StoredProcedureRunner.FluentStoredProcedureRunner`1[[PromakGateway.WebApi.Models.InactiveAccountsTransferModel, PromakGateway.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
I've seen here Castle Windsor - IoC registration for open generic interfaces? that there is an adapter of some kind but I don't know how it looks like. Thanks in advance.