我创建了一个在启动期间启动的应用程序,下面的代码如下.
重启后,该进程在进程管理器工具上运行,但我无法在屏幕上看到该应用程序.当我从启动注册表值打开相同的.exe文件时,程序运行完美.
// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
// Add the value in the registry so that the application runs at startup
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?
我有一个包含原始和自定义属性的类:
public class Version_1
{
public string Name { get; set; }
public int Age { get; set; }
public WeirdDad Weird { get; set; }
public MysteriousDad Mysterious { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在将来,我想用这样的方式扩展具有int属性的类以及我的一个自定义对象的自定义:
public class Version_2 : Version_1
{
public string IdentityCode { get; set; }
public WeirdChild Weird { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在Version_2类中,WeirdDad对象的外观已被其子项WeirdChild取代,因此我想替换它.在这个例子中,我将在Version_2类中包含WeirdDad和WeirdChild.
你会如何实现这个例子?
我正在使用IServiceCollection来为我的对象创建所需服务的列表。现在,我想实例化一个对象,并让DI容器解析该对象的依赖关系
例
// In my services config.
services
.AddTransient<IMyService, MyServiceImpl>();
// the object I want to create.
class SomeObject
{
public SomeObject(IMyService service)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何获得DI容器以创建类型SomeObject为注入依赖项的对象?(大概这就是对控制器的作用?)
注意:我不想存储SomeObject在服务集合中,我只想能够执行以下操作...
SomeObject obj = startup.ServiceProvider.Resolve<SomeObject>();
Run Code Online (Sandbox Code Playgroud)
...基本原理:我不必将所有控制器都添加到服务容器中,所以我也看不到为什么也必须添加SomeObject它!
我需要用 Math.random 生成 26 位数字,但是当我使用这个时:
Math.floor(Math.random() * 100000000000000000000000000) + 900000000000000000000000000
我得到9.544695043285823e+26