2016-06-01 3 views
1

私はnet.pipe経由で公開されているWCFサービスを持っています。このサービスは、次のようにホストされています。SVCファイルのないWCF依存性注入

var hosturi = new Uri("net.pipe://localhost/somewhere"); 
var host = new ServiceHost(typeof(Service), hosturi); 
var serviceBinding = new NetNamedPipeBinding 
{ 
    MaxReceivedMessageSize = int.MaxValue, // and maybe something else 
}; 

serviceBinding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas 
{ 
    MaxArrayLength = int.MaxValue, // and maybe something else 
}; 

host.AddServiceEndpoint(typeof(T), serviceBinding, string.Empty); 
host.Description.Behaviors.Add(
    new ServiceThrottlingBehavior 
    { 
     MaxConcurrentCalls = 5000, 
     MaxConcurrentInstances = 5000, 
     MaxConcurrentSessions = 5000 
    } 
); 
host.Open(); 

サービスのDIファクトリを指定したい場合は、コンストラクタの依存関係を注入します。

件名には多くの記事がありますが(例:https://msdn.microsoft.com/en-us/library/hh323725(v=vs.100).aspx)、絶対にすべてが.svcファイルを使用して工場を指定することをおすすめします。

コードでこれを行うにはどうすればよいですか?

+0

@Evkあなたは私をたくさん助けました!それはうまくいった。コメントを回答として追加すると、私はそれを受け入れます。 – zaitsman

答えて

1

サービスホストを自分で作成するので、ServiceHostFactory(ServceHostを作成する工場)は必要ありません。だから、記事からステップ4〜6をスキップして、あなたのホストに振る舞いを追加してください。

host.Description.Behaviors.Add(new DependencyInjectionServiceBehavior());