I'm moving some code from Castle 2.5.2 to 3.0, I have a set of predefined registrations (in my boot code) that does some stuff based on conventions such as:
container.Register
(
AllTypes.FromAssemblyInDirectory( new AssemblyFilter( "." ) )
.IncludeNonPublicTypes()
.Where( t => conventions.IsViewModel( t ) && !conventions.IsExcluded( t ) )
.WithService.Select( ( type, baseTypes ) => conventions.SelectViewModelContracts( type ) )
.Configure( r =>
{
r.Properties( PropertyFilter.IgnoreAll );
if( conventions.IsShellViewModel( r ) )
{
r.LifeStyle.Is( LifestyleType.Singleton );
}
else
{
r.LifeStyle.Is( LifestyleType.Transient …Run Code Online (Sandbox Code Playgroud) 有没有办法,使用EF6,注入自定义对象实例创建者?我需要做的是在美国化发生之前向EF提供实体实例.
基本上我希望能够使用非参数构造函数来定义我的POCO实体,因此为了能够使用DI aggreate,最终会使用EF持久化.
我知道我可以使用ObjectMaterialized事件来实现类似的东西:
var oc = ( this as IObjectContextAdapter ).ObjectContext;
oc.ObjectMaterialized += ( s, e ) =>
{
//resolve and inject dependencies here using e.g. public properties
};
Run Code Online (Sandbox Code Playgroud)
但我真的很想在构造函数上声明依赖项.
任何的想法?干杯,.m