本文整理汇总了C#中ISessionFactory.GetCurrentSession方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionFactory.GetCurrentSession方法的具体用法?C# ISessionFactory.GetCurrentSession怎么用?C# ISessionFactory.GetCurrentSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionFactory
的用法示例。
在下文中一共展示了ISessionFactory.GetCurrentSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckSession
private const string CurrentSessionKey = "nhibernate.current_session"; // added 3-31-15
#endregion Fields
#region Methods
// Bind, if necessary, the current HttpContext to NHibernate's ISession.
public static ISession CheckSession(ISessionFactory sf)
{
if (CurrentSessionContext.HasBind(sf))
return sf.GetCurrentSession();
var newSession = sf.OpenSession();
CurrentSessionContext.Bind(newSession);
return sf.GetCurrentSession();
}
示例2: OpenSessionIfRequired
public ISession OpenSessionIfRequired(ISessionFactory sessionFactory)
{
if (CatalogSessionContext.HasBind(sessionFactory))
{
return sessionFactory.GetCurrentSession();
}
else
{
lock (_syncRoot)
{
if (!CatalogSessionContext.HasBind(sessionFactory))
{
CatalogSessionContext.Bind(sessionFactory.OpenSession());
}
return sessionFactory.GetCurrentSession();
}
}
}
示例3: OpenSessionIfRequired
public static ISession OpenSessionIfRequired(ISessionFactory sessionFactory)
{
if (EventStoreSessionContext.HasBind(sessionFactory))
{
return sessionFactory.GetCurrentSession();
}
else
{
lock (_syncRoot)
{
if (!EventStoreSessionContext.HasBind(sessionFactory))
{
EventStoreSessionContext.Bind(sessionFactory.OpenSession());
logger.Info("EventStoreSessionContext.OpenSession");
}
return sessionFactory.GetCurrentSession();
}
}
}
示例4: GetSession
internal static ISession GetSession(ISessionFactory sessionFactory)
{
try {
return sessionFactory.GetCurrentSession();
}
catch (HibernateException) { }
ISession session = sessionFactory.OpenSession();
session.FlushMode = FlushMode.Always;
return session;
}
示例5: EmailService
public EmailService(string hostname, string sourceAddress, string contactAddress, bool testMode, ILogger logger, ISessionFactory sessionFactory)
{
defaultSmtpSender = new DefaultSmtpSender(hostname);
this.sourceAddress = sourceAddress;
this.contactAddress = contactAddress;
this.testMode = testMode;
this.logger = logger;
this.session = sessionFactory.GetCurrentSession();
}
示例6: GetHandlerSequence
private static HandlerSequence GetHandlerSequence(ISessionFactory sessionFactory, string name)
{
var session = sessionFactory.GetCurrentSession();
var sequence = session.Get<HandlerSequence>(name);
if (sequence != null)
return sequence;
sequence = new HandlerSequence(name);
session.Save(sequence);
return sequence;
}
示例7: Load
public static void Load( ISessionFactory sessionFactory )
{
LoadDependencies( sessionFactory );
var session = sessionFactory.GetCurrentSession();
if (!session.DataAlreadyLoaded<WorkItemStatus>())
{
CreateTestModelData( sessionFactory );
session.LoadIntoDatabase( ModelData );
}
}
示例8: NHibernateUnitOfWorkScope
public NHibernateUnitOfWorkScope(ISessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
ownsSession = !CurrentSessionContext.HasBind(sessionFactory);
if (ownsSession)
{
session = sessionFactory.OpenSession();
CurrentSessionContext.Bind(session);
return;
}
session = sessionFactory.GetCurrentSession();
}
示例9: GetRoles
public RoleDto[] GetRoles(long companyId)
{
var rolesService =ObjectFactory.GetInstance<IRolesService>();
_sessionFactory = ObjectFactory.GetInstance<IBusinessSafeSessionFactory>().GetSessionFactory();
CurrentSessionContext.Bind(_sessionFactory.OpenSession());
try
{
return rolesService.GetAllRoles(companyId).ToArray();
}
finally
{
_sessionFactory.GetCurrentSession().Dispose();
CurrentSessionContext.Unbind(_sessionFactory);
}
}
示例10: GetIncludingRoleByIdsAndCompanyId
public UserDto[] GetIncludingRoleByIdsAndCompanyId(Guid[] ids, long companyId)
{
_applicationLayerUserService =
ObjectFactory.GetInstance<BusinessSafe.Application.Contracts.Users.IUserService>();
_sessionFactory = ObjectFactory.GetInstance<IBusinessSafeSessionFactory>().GetSessionFactory();
CurrentSessionContext.Bind(_sessionFactory.OpenSession());
try
{
return _applicationLayerUserService.GetIncludingRoleByIdsAndCompanyId(ids, companyId).ToArray();
}
finally
{
_sessionFactory.GetCurrentSession().Dispose();
CurrentSessionContext.Unbind(_sessionFactory);
}
}
示例11: GetCurrentSession
public static ISession GetCurrentSession(ISessionFactory sessionFactory)
{
return sessionFactory.GetCurrentSession();
}
示例12: GetOrOpenSession
static ISession GetOrOpenSession(ISessionFactory sessionFactory)
{
if (NHibernate.Context.CurrentSessionContext.HasBind(sessionFactory))
return sessionFactory.GetCurrentSession();
var session = sessionFactory.OpenSession();
NHibernate.Context.CurrentSessionContext.Bind(session);
return session;
}
示例13: Init
private ServiceLocatorImpl Init()
{
var nhConfig = new Configuration();
Security.Configure<User>(nhConfig, SecurityTableStructure.Prefix);
SessionFactory = nhConfig.Configure().BuildSessionFactory();
CurrentSessionContext.Bind(SessionFactory.OpenSession());
//var s = new SchemaExport(nhConfig);
//s.SetOutputFile(@"c:\temp\out.txt");
//s.Execute(true, false, false);
NHibernate.Validator.Cfg.Environment.SharedEngineProvider.GetEngine().Configure();
var impl = new ServiceLocatorImpl();
ServiceLocator.SetLocatorProvider(() => impl);
impl.Add(typeof(CategoryRepository), () => new CategoryRepository(SessionFactory));
impl.Add(typeof(CustomerDemographicRepository), () => new CustomerDemographicRepository(SessionFactory));
impl.Add(typeof(CustomerRepository), () => new CustomerRepository(SessionFactory));
impl.Add(typeof(EmployeeRepository), () => new EmployeeRepository(SessionFactory));
impl.Add(typeof(OrderDetailRepository), () => new OrderDetailRepository(SessionFactory));
impl.Add(typeof(OrderRepository), () => new OrderRepository(SessionFactory));
impl.Add(typeof(ProductRepository), () => new ProductRepository(SessionFactory));
impl.Add(typeof(RegionRepository), () => new RegionRepository(SessionFactory));
impl.Add(typeof(ShipperRepository), () => new ShipperRepository(SessionFactory));
impl.Add(typeof(SupplierRepository), () => new SupplierRepository(SessionFactory));
impl.Add(typeof(TerritoryRepository), () => new TerritoryRepository(SessionFactory));
impl.Add(typeof(IStringConverter<Customer>), () => new CustomerStringConverter(new CustomerRepository(SessionFactory)));
impl.Add(typeof(IStringConverter<Product>), () => new ProductStringConverter(new ProductRepository(SessionFactory)));
impl.Add(typeof(IStringConverter<Category>), () => new CategoryStringConverter(new CategoryRepository(SessionFactory)));
impl.Add(typeof(NHibernate.Validator.Engine.ValidatorEngine), () => NHibernate.Validator.Cfg.Environment.SharedEngineProvider.GetEngine());
impl.Add(typeof(IAuthorizationRepository), () => new AuthorizationRepository(SessionFactory.GetCurrentSession()));
impl.Add(typeof(IPermissionsService), () => new PermissionsService(ServiceLocator.Current.GetInstance<IAuthorizationRepository>(), SessionFactory.GetCurrentSession()));
impl.Add(typeof(IAuthorizationService), () => new AuthorizationService(ServiceLocator.Current.GetInstance<IPermissionsService>(), ServiceLocator.Current.GetInstance<IAuthorizationRepository>()));
impl.Add(typeof(IPermissionsBuilderService), () => new PermissionsBuilderService(SessionFactory.GetCurrentSession(), ServiceLocator.Current.GetInstance<IAuthorizationRepository>()));
impl.Add(typeof(IEntityInformationExtractor<Customer>), () => new CustomerInformationExtractor());
impl.Add(typeof(IEntityInformationExtractor<Product>), () => new ProductInformationExtractor());
impl.Add(typeof(IEntityInformationExtractor<Category>), () => new CategoryInformationExtractor());
return impl;
}
示例14: LocalizationFilter
public LocalizationFilter(ISessionFactory sessionFactory)
{
CurrentSession = sessionFactory.GetCurrentSession();
}
示例15: DeletePostCommand
public DeletePostCommand(ISessionFactory sessionFactory)
{
_session = sessionFactory.GetCurrentSession();
}