2016-08-15 8 views
2

ServiceStack(4.0.62)はAppSettingsプロパティを登録して自動配線しません。私はこのような状況をデバッグする方法を知らず、誰かがそれを説明するかもしれない。ServiceStackは自動配線せずにAppSettingsを登録します

だから、私は(デフォルトのIoC Funqが使用されている)ServiceStackベースの自己ホスト型コンソールウィンドウアプリケーションを持っている:

SomeServiceののAppSettingsプロパティはまったく初期化されていません。

public class SomeService : Service 
    { 
     public IAppSettings AppSettings { get; set; } 

     public SomeResponse Get(SomeRequest request) 
     { 
      // Exception: AppSettings == null 
      var someValue = AppSettings.Get<string>("Key1"); 

      // ... 
     } 
    } 

方法できますか?どうしましたか?

答えて

2

ServiceStackはデフォルトでregister the IAppSettings in Funqです。すなわち、

期待どおりに動作している
class Program 
{ 
    static void Main(string[] args) 
    { 
     new AppHost().Init().Start("http://*:8088/"); 
     "ServiceStack Self Host with Razor listening at http://127.0.0.1:8088".Print(); 
     Process.Start("http://127.0.0.1:8088/"); 

     Console.ReadLine(); 
    } 
} 

public class AppHost : AppHostHttpListenerBase 
{ 
    public AppHost() : base("SomeServer", typeof(SomeService).Assembly) {} 
    public override void Configure(Container container) 
    { 
     SetConfig(new HostConfig { 
      DefaultContentType = MimeTypes.Json, 
      DebugMode = true, 
     }); 

     AppSettings = new DictionarySettings(new Dictionary<string, string> { 
      { "Key1", "Value1" }, 
      { "Key2", "Value2" }, 
     }); 
    } 
} 

[Route("/appsettings/{Key}")] 
public class SomeRequest 
{ 
    public string Key { get; set; } 
} 

public class SomeResponse 
{ 
    public string Value { get; set; } 
} 

public class SomeService : Service 
{ 
    public IAppSettings AppSettings { get; set; } 

    public SomeResponse Get(SomeRequest request) 
    { 
     return new SomeResponse { Value = AppSettings.Get<string>(request.Key) }; 
    } 
} 

で始まる:私はまた、新しいセルフホストコンソールアプリで例を使用して、これを確認した

StartUpErrorsがあり、AppHostの初期化を妨げる可能性があるかどうかを確認するには、?debug=requestinfoを確認してください。

+0

サポートありがとうございます。私はSSのドキュメントを読んで、デフォルトでIAppSettingsを登録しなければならないと確信していました。私はあなたのサンプルを試しました - すべて素晴らしいです。しかし、私の実際のプロジェクト登録では、まったく動作しません。登録を除くすべて。それは信じられない、 'StartUpErrors'は空です。[full log](http://pastebin.com/yMs18HQ8)を見てください。私はServiceStackのバージョンについて間違っていました。4.0.56でしたが、今は4.0.62ですが、何も変わりません。私の場合、AppHostは "http:// +:8088 /"で始まり、他のオプションは同じです。 –

+1

@AlexNewmanここから問題が何であるかは分かりません。 Google Docs、Dropboxなどの新しいGithubリポジトリや.zip共有で理想的に問題を見るためにローカルで実行できるスタンドアロンのレシピを公開できますか? – mythz

+0

それは私のせいでした、本当に悪いサービスのコンストラクタを使用してAppSettingsアクションを実装するアイデア質問は終了しました、ありがとうございました。 –

関連する問題