2011-01-12 6 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; 
    } 
} 

Ich bin neu in diesem Bereich. Meine Frage ist, wie man EnabledFeatures Werte zuweisen?Dependency Injection. Zuweisen von Werten zu IENUMERABLE

Dank Jeco

+0

Bitte formatieren Sie zumindest Ihren Code. –

+2

Ich habe es für ihn getan. (Er ist neu) – Aren

Antwort

2

Da Sie privaten Setter verwenden gewählt haben, ist Ihre einzige echte Option ist Konstruktor Injektion zu verwenden, die fast identisch ist, was Sie haben, außer dass Sie eine zusätzliche Überlastung des SampleTenant bieten würde Klasse, so dass es wie folgt aussehen würde mehr:

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

     EnabledFeatures = enabledFeatures; 
    } 
} 

Sie können hier mehr über Konstruktor vs Setter Injektion lesen: http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/