public static IServiceCollection AddSniffactorNhibernate(this IServiceCollection services, string connectionString)
{
Check.NotNull(connectionString);
configuration = Fluently.Configure()
.Database(OracleManagedDataClientConfiguration.Oracle10
.ConnectionString(connectionString)
Mappings(m => m.FluentMappings.AddFromAssemblyOf<ISniffactorMapping>());
services.AddSingleton(SessionFactory);
services.AddScoped(factory => configuration.BuildSessionFactory().OpenSession());
services.AddScoped(typeof(IRepository<>), typeof(NhRepositoryBase<>));
services.AddScoped(typeof(IUnitOfWork), typeof(NhUnitOfWork));
services;
}
And example a repo
public class KeywordDetectionViewRepository : NhRepositoryBase<KeywordDetectionView>, IKeywordDetectionViewRepository
{
private readonly ISession _session;
public KeywordDetectionViewRepository(ISession session) : base(session)
{
_session = session;
}
public async Task<List<KeywordDetectionView>> GetKeywordsAsync(string source, string tag, LanguageTypes languageTypes)
{
var query = _session.CreateCriteria<KeywordDetectionView>();
int keywordId = int.Parse(tag.Substring(2));
if (tag.StartsWith("k_"))
{
query.Add(Restrictions.Eq("KeywordId", keywordId));
}
else if (tag.StartsWith("v_"))
{
query.Add(Restrictions.Eq("VariationId", keywordId));
}
query.Add(Restrictions.Eq("SourceCode", source));
query.Add(Restrictions.Or(Restrictions.Eq("LanguageCode", languageTypes.ToString().ToLowerInvariant()), Restrictions.IsNull("LanguageCode")));
var result = await query.SetCacheable(false).ListAsync<KeywordDetectionView>();
return (List<KeywordDetectionView>)result;
}
}