如何归档自动注册,但忽略已经注册的任何类型?我在Simple Injector文档中引用了代码
var repositoryAssembly = typeof(SqlUserRepository).Assembly;
var registrations =
from type in repositoryAssembly.GetExportedTypes()
where type.Namespace == "MyComp.MyProd.BL.SqlRepositories"
where type.GetInterfaces().Any()
select new
{
Service = type.GetInterfaces().Single(),
Implementation = type
};
foreach (var reg in registrations)
{
// TODO: how to check reg.Service has already registered or not
container.Register(reg.Service, reg.Implementation, Lifestyle.Transient);
}
Run Code Online (Sandbox Code Playgroud)
例如,我具有ISampleRepository接口,并且在不同的程序集中有2个实现
项目1:工作
var container = new Container();
container.AutoRegistration();
Run Code Online (Sandbox Code Playgroud)
项目2:异常,因为ISampleRepository已注册
var container = new Container();
container.Register<ISampleRepository, OverrideSampleRepository>();
container.AutoRegistration();
Run Code Online (Sandbox Code Playgroud) 我使用 MySQL EF 6(MySQL.Data.Entity 包)连接到 MySQL DB。如果我使用构造函数 connectionStringName ,一切都可以:base("MyContext")。但如果我直接使用connectionString,它不起作用:base("server=localhost;port=3306;database=wordpress;uid=root")。应用程序引发错误System.ArgumentException: Keyword not supported: 'port'.
我的项目需要直接使用连接字符串。有谁知道如何修理它?谢谢
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class MyContext : DbContext
{
static MyContext()
{
Database.SetInitializer<MyContext>(null);
}
public MyContext()
//:base("server=localhost;port=3306;database=wordpress;uid=root;password=") not work
:base("MyContext") // it worked if using connectionStringName
{
}
}
Run Code Online (Sandbox Code Playgroud) 我按照教程http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/contact-manager-tutorial/1
Everthing看起来很好.但是在我导入EventAggregator(从'aurelia-event-aggregator'导入{EventAggregator};)之后,aurelia没有正确加载它.它是从文件夹dist(编译js文件夹)而不是jspm_packages加载的.
有人知道怎么解决吗?