本文整理汇总了C#中IServiceProvider.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.Resolve方法的具体用法?C# IServiceProvider.Resolve怎么用?C# IServiceProvider.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.Resolve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Context
public Context(IServiceProvider service)
{
Stream = ChunkedMemoryStream.Static();
Writer = Stream.GetWriter();
var dqm = service.Resolve<IDatabaseQueryManager>();
var factory = service.Resolve<IObjectFactory>().CreateInnerFactory();
factory.RegisterInterfaces(dqm.StartQuery(false));
Repository = factory.Resolve<IPersistableRepository<World>>();
BulkReader = factory.BulkRead(ChunkedMemoryStream.Static());
}
示例2: HttpListenerServer
public HttpListenerServer(IServiceProvider locator)
{
Listener = new HttpListener();
Listener.IgnoreWriteExceptions = true;
foreach (string key in ConfigurationManager.AppSettings.Keys)
{
if (key.StartsWith("HttpAddress", StringComparison.InvariantCultureIgnoreCase))
Listener.Prefixes.Add(ConfigurationManager.AppSettings[key]);
}
if (Listener.Prefixes.Count == 0)
Listener.Prefixes.Add("http://*:8999/");
Routes = locator.Resolve<Routes>();
var customAuth = ConfigurationManager.AppSettings["CustomAuth"];
if (!string.IsNullOrEmpty(customAuth))
{
var authType = Type.GetType(customAuth);
if (!typeof(HttpAuth).IsAssignableFrom(authType))
throw new ConfigurationErrorsException("Custom auth does not inherit from HttpAuth. Please inherit from " + typeof(HttpAuth).FullName);
Authentication = locator.Resolve<HttpAuth>(authType);
}
else Authentication = locator.Resolve<HttpAuth>();
}
示例3: ProvideValue
/// <inheritdoc />
public override object ProvideValue(IServiceProvider serviceProvider)
{
try
{
if (this.MemberType != null)
{
var resourceManager = Gu.Localization.ResourceManagers.ForType(this.MemberType);
return CreateBindingExpression(resourceManager, this.Member, serviceProvider);
}
if (string.IsNullOrEmpty(this.Member))
{
throw new InvalidOperationException("MarkupExtensionStaticMember");
}
var qnk = QualifiedNameAndKey.Parse(this.Member);
if (qnk.QualifiedName == null || qnk.Key == null)
{
return string.Format(Resources.UnknownErrorFormat, this.Member);
}
var type = serviceProvider.Resolve(qnk.QualifiedName);
if (type == null)
{
return string.Format(Resources.MissingResourcesFormat, this.Member);
}
var manager = Gu.Localization.ResourceManagers.ForType(type);
this.Member = qnk.Key;
return CreateBindingExpression(manager, this.Member, serviceProvider);
}
catch (Exception)
{
return string.Format(Resources.UnknownErrorFormat, this.Member);
}
}
示例4: HttpSocketServer
public HttpSocketServer(IServiceProvider locator)
{
this.Locator = locator;
var endpoints = new List<IPEndPoint>();
var networkType = AddressFamily.InterNetworkV6;
foreach (string key in ConfigurationManager.AppSettings.Keys)
{
if (key.StartsWith("HttpAddress", StringComparison.InvariantCultureIgnoreCase))
{
var addr = new Uri(ConfigurationManager.AppSettings[key]);
IPAddress ip;
if (!IPAddress.TryParse(addr.Host, out ip))
{
var ips = Dns.GetHostAddresses(addr.Host);
foreach (var i in ips)
if (i.AddressFamily == networkType)
endpoints.Add(new IPEndPoint(i, addr.Port));
if (endpoints.Count == 0 && ips.Length > 0)
{
if (ips[0].AddressFamily == AddressFamily.InterNetwork)
{
networkType = AddressFamily.InterNetwork;
foreach (var i in ips)
if (i.AddressFamily == networkType)
endpoints.Add(new IPEndPoint(i, addr.Port));
}
}
}
else endpoints.Add(new IPEndPoint(ip, addr.Port));
}
}
if (endpoints.Count == 0)
{
Console.WriteLine("Http address not found in config. Starting IPv6 on all interfaces");
endpoints.Add(new IPEndPoint(Socket.OSSupportsIPv6 ? IPAddress.IPv6Any : IPAddress.Any, 8999));
}
else if (endpoints.FindAll(it => it.AddressFamily == AddressFamily.InterNetwork).Count == endpoints.Count)
{
networkType = AddressFamily.InterNetwork;
}
else if (endpoints.FindAll(it => it.AddressFamily == AddressFamily.InterNetworkV6).Count != endpoints.Count)
{
throw new ConfigurationErrorsException(@"Unable to setup configuration for both IPv4 and IPv6. Use either only IPv4 or IPv6.
Please check settings: " + string.Join(", ", endpoints));
}
Socket = new Socket(networkType, SocketType.Stream, ProtocolType.Tcp);
//Socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0);
foreach (var ep in endpoints)
{
Socket.Bind(ep);
Console.WriteLine("Bound to: " + ep);
}
var customAuth = ConfigurationManager.AppSettings["CustomAuth"];
if (!string.IsNullOrEmpty(customAuth))
{
var authType = Type.GetType(customAuth);
if (!typeof(HttpAuth).IsAssignableFrom(authType))
throw new ConfigurationErrorsException("Custom auth does not inherit from HttpAuth. Please inherit from " + typeof(HttpAuth).FullName);
Authentication = locator.Resolve<HttpAuth>(authType);
}
else Authentication = locator.Resolve<HttpAuth>();
var routes = locator.Resolve<Routes>();
Context = new ThreadLocal<HttpSocketContext>(() => new HttpSocketContext("http://127.0.0.1/", MessageSizeLimit, routes));
var ca = ConfigurationManager.AppSettings["Revenj.HttpCapacity"];
Requests = !string.IsNullOrEmpty(ca)
? new BlockingCollection<RequestInfo>((int)Math.Log(int.Parse(ca), 2))
: new BlockingCollection<RequestInfo>();
}
示例5: QueueService
public QueueService(IServiceProvider locator)
{
Processor = locator.Resolve<QueueProcessor>();
InitializeComponent();
}
示例6: ReportingTests
public ReportingTests()
{
locator = Common.StartClient();
tService = locator.Resolve<ITemplaterService>();
rProxy = locator.Resolve<IReportingProxy>();
}
示例7: StandardTests
public StandardTests()
{
locator = Common.StartClient();
sProxy = locator.Resolve<IStandardProxy>();
}
示例8: MailService
public MailService(IServiceProvider locator)
{
Contract.Requires(locator != null);
this.Lookup = locator.Resolve<Func<string, IMailMessage>>();
}