本文整理汇总了C#中IServiceLocator.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceLocator.Resolve方法的具体用法?C# IServiceLocator.Resolve怎么用?C# IServiceLocator.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceLocator
的用法示例。
在下文中一共展示了IServiceLocator.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpServer
public HttpServer(ILogFactory logFactory, IServiceLocator locator)
{
Logger = logFactory.Create("Http server");
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://*:80/");
Listener.Prefixes.Add("https://*:443/");
}
Routes = new Routes(locator);
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>();
}
示例2: MailService
public MailService(IServiceLocator locator)
{
Contract.Requires(locator != null);
this.Serialization = locator.Resolve<ISerialization<byte[]>>();
this.Repository = locator.Resolve<Func<string, IMailMessage>>();
}
示例3: VerifyContainer
protected static void VerifyContainer(IServiceLocator serviceLocator, int expected)
{
Assert.That(serviceLocator.Resolve(typeof(EventStore)), Is.Not.Null);
var array = serviceLocator.ResolveAll(typeof(IEventHandler<AggregateChanged>));
Assert.That(array, Is.Not.Null);
Assert.That(array.Length, Is.EqualTo(expected));
if (expected == 1)
Assert.That(serviceLocator.Resolve(typeof(IEventHandler<AggregateChanged>)), Is.Not.Null);
}
示例4: ILGeneratorInstructionVisitor
internal ILGeneratorInstructionVisitor(
IServiceLocator serviceLocator,
IILGenerator generator,
IDictionary<VariableReference, LocalBuilder> locals)
: this(serviceLocator,
generator,
locals,
serviceLocator.Resolve<ITypeResolver>(),
serviceLocator.Resolve<IOpCodeMapper>())
{
}
示例5: RegisterMsmqOneWay
private void RegisterMsmqOneWay(AbstractRhinoServiceBusConfiguration c, IBusContainerBuilder b, IServiceLocator l)
{
var oneWayConfig = (OnewayRhinoServiceBusConfiguration)c;
b.RegisterSingleton<IMessageBuilder<Message>>(() => (IMessageBuilder<Message>)new MsmqMessageBuilder(
l.Resolve<IMessageSerializer>(),
l.Resolve<IServiceLocator>()));
b.RegisterSingleton<IOnewayBus>(() => (IOnewayBus)new MsmqOnewayBus(
oneWayConfig.MessageOwners,
l.Resolve<IMessageBuilder<Message>>(),oneWayConfig.ConfigurationSection.Bus.UseDeadLetterQueue));
}
示例6: GetMenuRegistryOrRegisterDefaultInstance
private static IMenuRegistry GetMenuRegistryOrRegisterDefaultInstance(IServiceLocator serviceLocator)
{
try
{
return serviceLocator.Resolve<IMenuRegistry>();
}
catch(ServiceResolutionException)
{
serviceLocator.Register<IMenuRegistry>(new MenuRegistry());
}
return serviceLocator.Resolve<IMenuRegistry>();
}
示例7: RegisterSqlQueuesTransport
private void RegisterSqlQueuesTransport(AbstractRhinoServiceBusConfiguration c, IBusContainerBuilder b, IServiceLocator l)
{
var busConfig = c.ConfigurationSection.Bus;
b.RegisterSingleton<IStorage>(() => new SqlStorage(busConfig.Path ?? QueueConnectionStringContainer.ConnectionString));
b.RegisterSingleton<ISubscriptionStorage>(() => new GenericSubscriptionStorage(
l.Resolve<IStorage>(),
c.Endpoint.ToString(),
l.Resolve<IMessageSerializer>(),
l.Resolve<IReflection>()));
b.RegisterSingleton<ITransport>(() => new SqlQueuesTransport(
c.Endpoint,
l.Resolve<IEndpointRouter>(),
l.Resolve<IMessageSerializer>(),
c.ThreadCount,
busConfig.Path ?? QueueConnectionStringContainer.ConnectionString,
c.NumberOfRetries,
l.Resolve<IMessageBuilder<MessagePayload>>()));
b.RegisterSingleton<IMessageBuilder<MessagePayload>>(() => new SqlQueuesMessageBuilder(
l.Resolve<IMessageSerializer>(),
l.Resolve<IServiceLocator>()));
}
示例8: RegisterSqlQueuesOneWay
private void RegisterSqlQueuesOneWay(AbstractRhinoServiceBusConfiguration c, IBusContainerBuilder b, IServiceLocator l)
{
var oneWayConfig = (OnewayRhinoServiceBusConfiguration)c;
var busConfig = c.ConfigurationSection.Bus;
b.RegisterSingleton<IMessageBuilder<MessagePayload>>(() => new SqlQueuesMessageBuilder(
l.Resolve<IMessageSerializer>(),
l.Resolve<IServiceLocator>()));
b.RegisterSingleton<IOnewayBus>(() => new SqlQueuesOneWayBus(
oneWayConfig.MessageOwners,
l.Resolve<IMessageSerializer>(),
busConfig.Path ?? QueueConnectionStringContainer.ConnectionString,
l.Resolve<IMessageBuilder<MessagePayload>>()));
}
示例9: RegisterRhinoQueuesOneWay
private void RegisterRhinoQueuesOneWay(AbstractRhinoServiceBusConfiguration c, IBusContainerBuilder b, IServiceLocator l)
{
var oneWayConfig = (OnewayRhinoServiceBusConfiguration)c;
var busConfig = c.ConfigurationSection.Bus;
b.RegisterSingleton<IMessageBuilder<MessagePayload>>(() => (IMessageBuilder<MessagePayload>)new RhinoQueuesMessageBuilder(
l.Resolve<IMessageSerializer>(),
l.Resolve<IServiceLocator>()));
b.RegisterSingleton<IOnewayBus>(() => (IOnewayBus)new RhinoQueuesOneWayBus(
oneWayConfig.MessageOwners,
l.Resolve<IMessageSerializer>(),
busConfig.QueuePath,
busConfig.EnablePerformanceCounters,
l.Resolve<IMessageBuilder<MessagePayload>>()));
}
示例10: GetTypeCatalog
public static ITypeCatalog GetTypeCatalog(IServiceLocator serviceLocator)
{
var typeCatalog = serviceLocator.Resolve<ITypeCatalog>();
if (typeCatalog != null)
{
return typeCatalog;
}
var assemblies = serviceLocator.Resolve<List<Assembly>>();
if (assemblies == null || assemblies.Count < 1)
{
assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
}
serviceLocator.RegisterInstance(assemblies);
typeCatalog = new AppDomainTypeCatalog(assemblies);
serviceLocator.Register(() => typeCatalog);
return typeCatalog;
}
示例11: GetEmbeddedViewResolver
/// <summary>
/// Gets the <see cref="IEmbeddedViewResolver"/> resolver for the system.
/// </summary>
/// <param name="serviceLocator"></param>
/// <returns></returns>
protected virtual IEmbeddedViewResolver GetEmbeddedViewResolver(IServiceLocator serviceLocator) {
try {
return serviceLocator.Resolve<IEmbeddedViewResolver>();
}
catch {
return new EmbeddedViewResolver();
}
}
示例12: RegisterRhinoQueuesTransport
private void RegisterRhinoQueuesTransport(AbstractRhinoServiceBusConfiguration c, IBusContainerBuilder b, IServiceLocator l)
{
var busConfig = c.ConfigurationSection.Bus;
var fileManagerConfiguration = new QueueManagerConfiguration();
b.RegisterSingleton<ISubscriptionStorage>(() => (ISubscriptionStorage)new FileSubscriptionStorage(
busConfig.SubscriptionPath,
l.Resolve<IMessageSerializer>(),
l.Resolve<IReflection>()));
b.RegisterSingleton<ITransport>(() => (ITransport)new RhinoFilesTransport(
c.Endpoint,
l.Resolve<IEndpointRouter>(),
l.Resolve<IMessageSerializer>(),
c.ThreadCount,
busConfig.QueuePath,
c.IsolationLevel,
c.NumberOfRetries,
busConfig.EnablePerformanceCounters,
l.Resolve<IMessageBuilder<MessagePayload>>(),
fileManagerConfiguration));
b.RegisterSingleton<IMessageBuilder<MessagePayload>>(() => (IMessageBuilder<MessagePayload>)new RhinoFilesMessageBuilder(
l.Resolve<IMessageSerializer>(),
l.Resolve<IServiceLocator>()));
b.RegisterSingleton<QueueManagerConfiguration>(() => fileManagerConfiguration);
}
示例13: RegisterViewEngine
protected virtual void RegisterViewEngine(IServiceLocator locator) {
try {
var engineManager = locator.Resolve<IViewEngineManager>();
if (engineManager == null) return;
engineManager.RegisterEngines();
}
catch { }
}
示例14: MainWindow
/// <summary>
///
/// </summary>
/// <param name="locator"></param>
/// <param name="resetEvent">invoked after all region defined</param>
public MainWindow(IServiceLocator locator, ManualResetEvent resetEvent)
{
_locator = locator;
InitializeComponent();
var regionManager = locator.Resolve<RegionManager>();
regionManager.AttachRegion("mainTab", OurTabcontrol);
resetEvent.Set();
}
示例15: Register
public void Register(IServiceLocator locator)
{
locator.Register<IAdminAccountRepository, AdminAccountRepository>();
locator.Register<IAdminAccountListPageViewModelMapper, AdminAccountListPageViewModelMapper>();
locator.Register<IAdminAccountEditFormStore, AdminAccountEditFormStore>();
locator.Register<IAdminAccountIdGenerator, AdminAccountIdGenerator>();
locator.Register<IDatabaseRetriever>(() =>
{
var adminAccountSettings = locator.Resolve<IAdminAccountSettings>();
return new DatabaseRetriever(adminAccountSettings.ConnectionString);
});
locator.Register<IPasswordHasher>(() =>
{
var adminAccountSettings = locator.Resolve<IAdminAccountSettings>();
return new PasswordHasher(adminAccountSettings);
});
}