huge
huge
Explore posts from servers
CC#
Created by huge on 2/2/2024 in #help
get scoped service
public static IServiceCollection RegisterCommandHandlers(this IServiceCollection services, Assembly assembly, Type compareType)
{
services.AddScoped<ICommandHandler<CreateCommand>, CreateCommandHandler>(); // i have multiple registrations , this is a sample one jic

CommandDispatcher dispatcher = new();
foreach (var commandHandlerType in assembly.GetTypes()
.Where(type => type.GetInterfaces()
.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler<>))))
{
var commandType = commandHandlerType.GetInterfaces()
.Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler<>))
.GetGenericArguments()[0];
Type genericType = typeof(ICommandHandler<>).MakeGenericType(commandType);
var commandHandler = services.BuildServiceProvider().GetRequiredService(genericType); //tried doing this beacuse idk what im doing

var handleAsyncMethod = commandHandlerType.GetMethod("HandleAsync");

if (handleAsyncMethod != null)
{
var handleDelegate = (Func<object, Task>)handleAsyncMethod.CreateDelegate(
typeof(Func<object, Task>).MakeGenericType(commandType, typeof(Task)),
commandHandler);

dispatcher.RegisterHandler(commandType, handleDelegate);
Console.Write("Registered a delegate");
}

else
{
Console.Write("here");
}
}

services.AddSingleton<ICommandDispatcher>(_ => dispatcher);
return services;

}
public static IServiceCollection RegisterCommandHandlers(this IServiceCollection services, Assembly assembly, Type compareType)
{
services.AddScoped<ICommandHandler<CreateCommand>, CreateCommandHandler>(); // i have multiple registrations , this is a sample one jic

CommandDispatcher dispatcher = new();
foreach (var commandHandlerType in assembly.GetTypes()
.Where(type => type.GetInterfaces()
.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler<>))))
{
var commandType = commandHandlerType.GetInterfaces()
.Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICommandHandler<>))
.GetGenericArguments()[0];
Type genericType = typeof(ICommandHandler<>).MakeGenericType(commandType);
var commandHandler = services.BuildServiceProvider().GetRequiredService(genericType); //tried doing this beacuse idk what im doing

var handleAsyncMethod = commandHandlerType.GetMethod("HandleAsync");

if (handleAsyncMethod != null)
{
var handleDelegate = (Func<object, Task>)handleAsyncMethod.CreateDelegate(
typeof(Func<object, Task>).MakeGenericType(commandType, typeof(Task)),
commandHandler);

dispatcher.RegisterHandler(commandType, handleDelegate);
Console.Write("Registered a delegate");
}

else
{
Console.Write("here");
}
}

services.AddSingleton<ICommandDispatcher>(_ => dispatcher);
return services;

}
10 replies
CC#
Created by huge on 12/3/2023 in #help
i have to restart omnisharp every time
didnt know devkit existed , is dev kit just for vs code? because ive moved on from vs code after i had to Ctrl +P , Restart Omnisharp every 30 seconds
10 replies
CC#
Created by huge on 2/23/2023 in #help
namespace fking me up
ty
10 replies
CC#
Created by huge on 2/23/2023 in #help
namespace fking me up
and it worked
10 replies
CC#
Created by huge on 2/23/2023 in #help
namespace fking me up
i deleted some folders
10 replies
CC#
Created by huge on 2/23/2023 in #help
namespace fking me up
Oh
10 replies
CC#
Created by huge on 2/23/2023 in #help
namespace fking me up
that would be true
10 replies
CC#
Created by huge on 2/23/2023 in #help
namespace fking me up
i dont have a type or class but i do have a couple of folders
10 replies
CC#
Created by huge on 8/27/2022 in #help
The process cannot access the file 'homedeepinsideRiderProjectsxplattestxplattestobjDebugnet
checked issues
17 replies
CC#
Created by huge on 8/27/2022 in #help
The process cannot access the file 'homedeepinsideRiderProjectsxplattestxplattestobjDebugnet
the problem actually has been existing for more than a year
17 replies
CC#
Created by huge on 8/27/2022 in #help
The process cannot access the file 'homedeepinsideRiderProjectsxplattestxplattestobjDebugnet
@tebeco sry forgot to close
17 replies
CC#
Created by huge on 8/27/2022 in #help
The process cannot access the file 'homedeepinsideRiderProjectsxplattestxplattestobjDebugnet
yea ive encountered my problems
17 replies
CC#
Created by huge on 8/27/2022 in #help
The process cannot access the file 'homedeepinsideRiderProjectsxplattestxplattestobjDebugnet
The process cannot access the file '/home/deepinside/RiderProjects/xplattest/xplattest/obj/Debug/netstandard2.0/Avalonia/original.pdb' because it is being used by another process.
The process cannot access the file '/home/deepinside/RiderProjects/xplattest/xplattest/obj/Debug/netstandard2.0/Avalonia/original.pdb' because it is being used by another process.
17 replies