本文整理汇总了C#中IContext.GetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.GetInstance方法的具体用法?C# IContext.GetInstance怎么用?C# IContext.GetInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.GetInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildUserSession
private static UserSession BuildUserSession(IContext context)
{
var request = context.GetInstance<HttpRequest>();
if (!request.Cookies.AllKeys.Contains(UserSession.CookieName))
return null;
// ReSharper disable once PossibleNullReferenceException
var userSessionId = Guid.Parse(request.Cookies[UserSession.CookieName].Value);
var authenticationDao = context.GetInstance<AuthenticationDao>();
return authenticationDao.LoadUserSession(userSessionId);
}
示例2: OpenSession
static IDocumentSession OpenSession(IContext ctx)
{
var bus = ctx.GetInstance<IBus>();
string environmentId = null;
if (bus.CurrentMessageContext != null && bus.CurrentMessageContext.Headers.ContainsKey("EnvironmentId"))
environmentId = bus.CurrentMessageContext.Headers["EnvironmentId"];
var store = ctx.GetInstance<IDocumentStore>();
return RavenSession.OpenSession(environmentId, store);
}
示例3: Process
public object Process(object target, IContext context)
{
var clockedElement = (IClockedElement)target;
context.GetInstance<IClock>().Subscribe(clockedElement);
return target;
}
示例4: CreateBus
private IServiceBus CreateBus(IContext context)
{
return ServiceBusFactory.New(sbc =>
{
sbc.UseRabbitMq();
sbc.ReceiveFrom("rabbitmq://localhost/" + QueueName);
sbc.UseRabbitMqRouting();
sbc.Subscribe(c => c.LoadFrom(context.GetInstance<IContainer>()));
});
}
示例5: CreateFluentConfiguration
private FluentConfiguration CreateFluentConfiguration(IContext context)
{
var databaseProvider = context.GetInstance<IDatabaseAdapter>();
//// TODO: get list of mappings assembly
return Fluently
.Configure()
.ExposeConfiguration(x => x.SetProperty("cache.use_second_level_cache", "true"))
.ExposeConfiguration(x => x.SetProperty("cache.use_query_cache", "true"))
.ExposeConfiguration(x => x.SetProperty("cache.provider_class", typeof(FeliceCacheProvider).AssemblyQualifiedName))
.Database(databaseProvider.GetHibernateDriver(AppSettings.ConnectionString))
.Mappings(ConfigureMappings);
}
示例6: GetCurrentUser
private string GetCurrentUser(IContext context)
{
try
{
var httpContext = context.GetInstance<HttpContextBase>();
if (httpContext == null) return null;
if (httpContext.User == null) return null;
var user = httpContext.User;
if (!user.Identity.IsAuthenticated) return null;
return user.Identity.Name;
}
catch (Exception ex)
{
throw new Exception("Error trying to determine the current user.", ex);
}
}
示例7: BuildCryptographer
static ICryptographer BuildCryptographer(IContext context)
{
var processName = Process.GetCurrentProcess()
.ProcessName.ToLower();
if (processName.Contains("w3wp") || processName.Contains("aspnet_wp") || processName.Contains("iisexpress"))
return new WebCryptographer();
var cryptoConfig = context.GetInstance<ICryptoConfigurationProvider>();
var encryptionAlgorithm = cryptoConfig.EncryptionAlgorithm;
var hashAlgorithm = cryptoConfig.HashAlgorithm;
var encryptionKey = cryptoConfig.EncryptionKey;
var hmacKey = cryptoConfig.HmacKey;
var generic = typeof (Cryptographer<,>);
var specific = generic.MakeGenericType(new[] {encryptionAlgorithm, hashAlgorithm});
var ci = specific.GetConstructor(new[] {typeof (byte[]), typeof (byte[])});
var o = ci.Invoke(new object[] {encryptionKey, hmacKey});
return o.As<ICryptographer>();
}
示例8: BuildRestClient
private static RestClient BuildRestClient(IContext context)
{
var settings = context.GetInstance<Settings>();
return new RestClient(settings.ApiUrl.OriginalString);
}
示例9: Process
public object Process(object target, IContext context)
{
context.GetInstance<IEventAggregator>().Subscribe(target);
return target;
}
示例10: Process
public object Process(object target, IContext context)
{
var eventPublisher = context.GetInstance<IEventPublisher>();
eventPublisher.Subscribe(target);
return target;
}
示例11: Process
public object Process(object target, IContext context)
{
context.GetInstance<IEventAggregator>().AddListener(target);
return target;
}
示例12: Process
public object Process(object target, IContext context)
{
context.GetInstance<IDistributor>().AddListener(target);
return target;
}
示例13: CreateSessionFactory
private ISessionFactory CreateSessionFactory(IContext context)
{
return context.GetInstance<FluentConfiguration>().BuildSessionFactory();
}
示例14: CreateSession
private static ISession CreateSession(IContext x)
{
var session = x.GetInstance<ISessionFactory>().OpenSession();
session.FlushMode = FlushMode.Commit;
return session;
}
示例15: CreateBus
private static IBus CreateBus(IContext context)
{
return new MassTransitPublisher(context.GetInstance<IServiceBus>());
}