我需要将 StructureMap 代码转换为 Ninject(以支持我的托管服务提供商,因为它们仅支持在中等信任下运行的应用程序)。我在 StructureMap 中的基本寄存器是:
ObjectFactory.Initialize(x =>
{
x.For<IDbConnection>()
.HttpContextScoped()
.Use(() =>
{
var constr = ConfigurationManager
.ConnectionStrings["conn"].ConnectionString;
var conn = new SqlConnection(constr);
conn.Open();
return conn;
});
x.FillAllPropertiesOfType<IDbConnection>();
x.For<ICurrent>().Use<Current>();
x.For<ILogger>().Use<Logger>();
x.For<IMembershipService>().Use<SpaceMembership>();
x.For<IFormsAuthenticationService>()
.Use<FormsAuthenticationService>();
x.Scan(sc =>
{
sc.Assembly("Space360.DB");
sc.AddAllTypesOf(typeof(IRepository<>));
sc.WithDefaultConventions();
});
});