2011-01-12 8 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に割り当てます

おかげ Jeco

+0

コードを少なくともフォーマットしてください。 –

+2

私は彼のためにそれをやった。 (彼は新しいです) – Aren

答えて

2

プライベートセッターを使用することを選択したので、あなたの唯一の現実的な選択肢は、あなたがSampleTenantに追加のオーバーロードを提供したい除いて、あなたが持っているものとほぼ同じですコンストラクタ・インジェクションを使用することですこのクラスでは、より次のようになりますので:

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

     EnabledFeatures = enabledFeatures; 
    } 
} 

あなたがここにセッターインジェクション対コンストラクタ詳細を読むことができます:http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/

0

チェックをこのネット依存インジェクタOU t。あなたが必要とするものに役立つかもしれません。

http://ninject.org/