GitHub Action
DMH Debug Method Helper
Welcome all,
We have designed this project to help developers like us. who are spending most of their time in debugging the code.
Why should we code to test a method, why not use reflection. based on this idea only this project was built.
Follow all the simple steps once and you don't want to write any code after to test your methods.
Steps to follow:
-
Download DMH and install this extension for Visual studio 2015/2017/2019 & 2019 community edition, else open visual studio and open extensions window and search for DMH and download fist item.
-
Restart Visual studio and open your c# project.
-
Resolve dependency Interface using UI Map dependency/skip all dependency/map by code(using autofac etc.),
-
You can skip all dependency and Map your Interface by code, like you do for your test project,
If you project is big and you cannot map using UI then this way of mapping will be really helpful.
(note: please don't change namespace(LouckHome), class and method name else auto mapping will not work)
//Add this code in your startup project selected in UI
using Autofac;//optional based on reliever you are using
namespace LuckyHome//do change else we cannot find
{
public class LuckyHomeInterfaceClassMapper
{
private readonly static ILifetimeScope scope;
static LuckyHomeInterfaceClassMapper()
{
HttpConfiguration config = new HttpConfiguration();
scope = AutofacConfig.Register(config, false).BeginLifetimeScope();
//AutofacConfig.Register class is some thing you have to create and register your dependency
//In you case you can have different class name or different way of registering, you can do it that way.
//not only autofac you can use any resolver
//If you want you can even do mock for some type
}
//where in Run method input type will be of interface and output object you have to resolver and send back as class.
public object Run(Type type/*interface*/)
{
var output = scope.Resolve(type);
//If you want you can even do mock for some type
if (output == null)
{
}
return output;//class
}
}
}
- Set input parameter values for that method
-
Startup Project config will be used by default if you want you can also use a custom config For custom config create new file name "luckyhome.config" in startup project output directory and add you configuration
-
Start debugging in few seconds
Not just for web services or web API it supports all frameworks written in c#.
To get Core Dependency supported please use below code.
(note: please don't change namespace(LouckHome), class and method name else auto mapping will not work)
//Add this code in your startup project selected in UI
namespace LuckyHome
{
public class LuckyHomeInterfaceClassMapper
{
// private readonly static ILifetimeScope scope;
//static IConfiguration configuration;
private static IServiceProvider serviceProvider;
static LuckyHomeInterfaceClassMapper()
{
var services = new ServiceCollection();
IConfiguration tempIConfiguration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
.AddUserSecrets("e3dfcccf-0cb3-423a-b302-e3e92e95c128")
.AddEnvironmentVariables()
.Build();
services.AddScoped<IConfiguration>(_ => tempIConfiguration);
//services.AddTransient<IframeInterface, FrameInterface>(); //based on you class and interface name input will change
// Simple configuration object injection (no IOptions<T>)
//services.Configure<PositionOptions>(tempIConfiguration.GetSection(
// PositionOptions.Position));//based on Configuration class name input will change
services.AddLogging(builder => builder.AddConsole());
serviceProvider = services.BuildServiceProvider();
}
public object Run(Type type)
{
object output = serviceProvider.GetService(type);
if (output == null)
{
output = serviceProvider.GetRequiredService(type);
if (output == null)
throw new NotImplementedException();
}
return output;
}
}
}
appsettings.json change the property to copy to output directory
Finally edit core project csproj file to run in windows 10 by adding this code.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
Please share your valuable feedback, Thanks in advance.