2011-01-12 70 views
1
public interface IFeature 
{ 
    string FeatureName { get; set; } 
} 

public interface IFeatureRegistry 
{ 
    IEnumerable<IFeature> Features { get; set; } 

    bool IsEnabled(IEnumerable<string> featurePath); 
} 

public interface IApplicationTenant 
{ 
    string ApplicationName { get; } 
    IFeatureRegistry EnabledFeatures { get; } 
} 

public abstract class AbstractApplicationTenant : IApplicationTenant 
{ 
    public string ApplicationName { get; protected set; } 
    public IFeatureRegistry EnabledFeatures { get; protected set; } 
} 

public class SampleTenant : AbstractApplicationTenant 
{ 
    public SampleTenant() 
    { 
     ApplicationName = "Sample 1"; 

     EnabledFeatures = null; 
    } 
} 

我是这个领域的新手。我的问题是如何将值分配给EnabledFeatures依赖注入。将值分配给IENUMERABLE

感谢 捷虹

+0

请至少格式化您的代码。 – 2011-01-12 00:38:18

回答

2

既然你已经选择使用私有制定者,你的唯一真正的选择是使用构造函数注入这几乎是相同的,你有什么,除了你提供额外的过载到SampleTenant类,所以它看起来更像是这样的:

public class SampleTenant : AbstractApplicationTenant 
{ 
    public SampleTenant(IFeatureRegistry enabledFeatures) 
    { 
     ApplicationName = "Sample 1"; 

     EnabledFeatures = enabledFeatures; 
    } 
} 

你可以阅读更多关于构造VS setter注入的位置:http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/