インスタンスを StructureMap に要求し、すぐにパラメーターを渡して、(渡したパラメーターを使用して) インスタンスを構成しようとしていますが、これを行う方法がわかりません!
ここにコードがあります。私がやりたいことを理解するのは簡単です。
class MyRegistry : Registry {
public MyRegistry() {
// Use a new Connection for each instance
For<ISQLRepositoryCommands>().Use(x => new SQLRepositoryCommands(DatabaseConnections.NewSqlConnection()));
// WHAT I Want to do is.. remove the line above of code and let only this.
For<ISQLRepositoryCommands>()
.Use(x => {
if( x.arguments != null ) {
// Specific connection passed by parameter
return new SQLRepositoryCommands( (SqlConnection) x.arguments[0]);
}
// default connection
return new SQLRepositoryCommands(DatabaseConnections.NewSqlConnection());
});
}
}
メイン
public static class StartUseStructureMap {
public static void Main() {
// SQLRepositoryCommands with default connection associated
var def = ObjectFactory.GetInstance<ISQLRepositoryCommands>();
// SQLRepositoryCommands with custom connection associated
var personalizedConnection = new SqlConnection("cstring");
var personalized = ObjectFactory.GetInstance<ISQLRepositoryCommands>(new Arguments[] { new Argument(personalizedConnection) };
}
}