Skip to content

Instantly share code, notes, and snippets.

View maliming's full-sized avatar
🏠
Working from home

maliming

🏠
Working from home
View GitHub Profile
@brianlow
brianlow / FindConflictingReferences.cs
Created January 3, 2012 03:04
Find conflicting assembly references
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace MyProject
{
[TestFixture]
@haacked
haacked / ThrowsAsync.cs
Created January 24, 2013 00:37
An async version of xUnit's Async.Throws. Use it like so: await ThrowsAsync<AuthenticationException>(async () => await obj.GetStuffAsync());
public async static Task<T> ThrowsAsync<T>(Func<Task> testCode) where T : Exception
{
try
{
await testCode();
Assert.Throws<T>(() => { }); // Use xUnit's default behavior.
}
catch (T exception)
{
return exception;
@hikalkan
hikalkan / AccountController.cs
Created January 13, 2016 16:25
Adding a new property to session
//Add new property to claims on login
private async Task SignInAsync(User user, ClaimsIdentity identity = null, bool rememberMe = false)
{
if (identity == null)
{
identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
}
identity.AddClaim(new Claim("Application_UserEmail", user.EmailAddress)); //SETTING NEW PROPERTY
using System;
using System.IO;
using System.Linq;
using System.Text;
namespace AbpWebSite.Templates
{
/// <summary>
/// Used to rename a solution
/// </summary>
@hikalkan
hikalkan / AbpSessionExtensions.cs
Created June 20, 2016 16:06
Creating an overridable session for ABP
using System;
using Abp.Runtime.Session;
namespace Abp.Temp
{
public static class AbpSessionExtensions
{
public static IDisposable Override(this IAbpSession abpSession, int? tenantId, long? userId)
{
var overridableSession = abpSession as OverridableSession;
@ismcagdas
ismcagdas / MyAppSession.cs
Last active April 27, 2021 13:18
How to add custom field to AbpSession in ASP.NET Core
//Define your own session and add your custom field to it
//Then, you can inject MyAppSession and use it's new property in your project.
public class MyAppSession : ClaimsAbpSession, ITransientDependency
{
public MyAppSession(
IPrincipalAccessor principalAccessor,
IMultiTenancyConfig multiTenancy,
ITenantResolver tenantResolver,
IAmbientScopeProvider<SessionOverride> sessionOverrideScopeProvider) :
base(principalAccessor, multiTenancy, tenantResolver, sessionOverrideScopeProvider)
@hikalkan
hikalkan / MyDbContext.cs
Created March 29, 2018 10:51
How to map a dictionary property of an entity to a string field of a table in Entity Framework Core v2.1+
public class MyDbContext : DbContext
{
public DbSet<User> Users { get; set; }
public MyDbContext(DbContextOptions<MyDbContext> options)
: base(options)
{
}
@ebicoglu
ebicoglu / abp-oracle-integration.md
Last active November 16, 2021 11:25
Integration guide to use Oracle with ABP Framework
@ebicoglu
ebicoglu / sql-find-missing-index.sql
Created August 11, 2020 10:09
Finds missing indexes for SQL
SELECT
OBJECT_NAME(id.[object_id], db.[database_id]) AS [Table]
,id.[equality_columns] AS [EqualityColumns]
,id.[inequality_columns] AS [InEqualityColumns]
,id.[included_columns] AS [IncludedColumns]
,gs.[avg_total_user_cost] AS [UserCost] -- Average cost of the user queries that could be reduced by the index in the group.
,gs.[avg_user_impact] AS [QueryBoostImpact] -- The value means that the query cost would on average drop by this percentage if this missing index group was implemented.
,gs.[user_seeks] * gs.[avg_total_user_cost] * (gs.[avg_user_impact] * 0.01) AS [IndexAdvantage]
,'CREATE INDEX [IX_' + OBJECT_NAME(id.[object_id], db.[database_id]) + '_' + REPLACE(REPLACE(REPLACE(ISNULL(id.[equality_columns], ''), ', ', '_'), '[', ''), ']', '') + CASE