【发布时间】:2016-06-03 22:17:49
【问题描述】:
我有一个通过 net.pipe 公开的 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();
我想为我的 Service 实例指定 DI 工厂,获取注入的任何构造函数依赖项。
虽然有很多关于该主题的文章(例如,这里:https://msdn.microsoft.com/en-us/library/hh323725(v=vs.100).aspx),但绝对所有文章都建议使用 .svc 文件指定工厂。
如何在代码中做到这一点?
【问题讨论】:
-
@Evk 你帮了我很多!那行得通。如果您将评论添加为答案,我会接受。
标签: c# wcf inversion-of-control