小编Ste*_*ven的帖子

Unity3D localscale问题

如下代码:

Debug.LogWarning("updating scale fix, scalefactor: "+scaleFactor+" - Current scale is: "+cell.transform.localScale.x);
cell.transform.localScale.Set (scaleFactor,scaleFactor,scaleFactor);
Debug.LogWarning("Scale after fix: " + cell.transform.localScale.x);
Run Code Online (Sandbox Code Playgroud)

产生以下输出:

updating scale fix, scalefactor: 0.9 - Current scale is 0.8921105
UnityEngine.Debug:LogWarning(Object)

Scale after fix: 0.8921105
UnityEngine.Debug:LogWarning(Object)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我只是假设由于这些事情是紧接着发生的,因此应该更新规模。还是在框架完成之后发生?

任何帮助表示赞赏。

c# transform scale unity-game-engine

2
推荐指数
1
解决办法
7843
查看次数

在Unity中闪烁游戏对象

如何使用SetActiveRecursively(Moment = 1秒)在Unity中创建闪烁对象.

我的例子(改变):

public GameObject flashing_Label;

private float timer;

void Update() {

while(true)
{
flashing_Label.SetActiveRecursively(true);
timer = Time.deltaTime;

  if(timer > 1)       
          {
            flashing_Label.SetActiveRecursively(false);
            timer = 0;        
          }   
 }

}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine ngui unityscript

2
推荐指数
1
解决办法
9556
查看次数

删除Convert.ToDecimal依赖(依赖注入)

我目前正在学习依赖注入,以便使用MVC创建更易于维护的代码.我已经向我的控制器注入模型和计算器服务,而不是具有新的依赖性.

我在构造函数中有一些Convert.ToDecimal调用,并且不知道是否需要担心使用依赖注入来移除静态方法调用,这是一种DI设计气味.删除太远了吗?

private readonly ICalculationService _calculation;
private readonly ICalculatorModelService _calculatormodel;

public CalculatorController(ICalculationService calculation,
    ICalculatorModelService calculatormodel) {
    _calculation = calculation;
    _calculatormodel = calculatormodel;
}

public ActionResult Index() {
    var model = _calculatormodel;
    return View(model);
}

public PartialViewResult Calculate(string submit, string txtValue, 
    string value1) {
    var model = _calculatormodel;
    if (submit == "+")
    {
        if (Session["value1"] == null)
            Session.Add("value1",Convert.ToDecimal(txtValue));
        else
            Session["value1"] = value1;
    }
    else if (submit == "=")
    {
        if (Session["value1"] == null)
        Session.Add("value1", 0);

        model.Result = _calculation.Calculate(Convert
            .ToDecimal(Session["value1"]), Convert.ToDecimal(txtValue));
    } …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection solid-principles

2
推荐指数
1
解决办法
80
查看次数

使用 Simple Injector 自动注册通用存储库

我找不到使用 Simple Injector (v3) 注册通用存储库的方法。

我有一个基类GenericRepository<T>和一个接口ILinkRepository。基类和接口都实现IGenericRepository<T>. 我对存储库的实现LinkRepository继承GenericRepository<T>并实现了ILinkRepository.

然后我有一个服务类,它通过构造函数获取存储库LinkService(ILinkRepository repository)

我想通过 Simple Injector 自动注册我的通用存储库,所以我试过这个:

container.Register(typeof(IGenericRepository<>), new []
{
    typeof(IGenericRepository<>).Assembly
});
Run Code Online (Sandbox Code Playgroud)

当 Simple Injector 尝试验证我的容器时,出现错误:

LinkService 类型的构造函数包含名称为“repository”且类型为 ILinkRepository 的未注册参数。请确保 ILinkRepository 已注册...

那么有没有其他方法可以告诉 Simple Injector ILinkRepository 是一个 LinkRepository 实例而无需像下面那样直接注册它?

container.Register<ILinkRepository, LinkRepository>()
Run Code Online (Sandbox Code Playgroud)

c# generics dependency-injection simple-injector

2
推荐指数
1
解决办法
1547
查看次数

设置 Topshelf 和 Quartz.Net 控制台应用程序时从 Ninject 访问对象

在配置 Ninject/Topshelf/Quartz.Net 设置期间使用对象的正确方法是什么?

我创建了一个IocModule将我的接口绑定到一个具体类:

public class IocModule : NinjectModule
{
    public override void Load()
    {
        Bind<IConfiguration>().To<JsonConfiguration>().InSingletonScope();
    }
}
Run Code Online (Sandbox Code Playgroud)

在运行时间的 Quartz.Net 设置期间,我需要此配置中的一些值,但使用IConfiguration configuration = new JsonConfiguration();似乎不是执行此操作的正确方法:

namespace Question {
    public class Program {
        public static int Main(string[] args) {
            var exitCode = HostFactory.Run(c => {
                c.UseNinject(new IocModule());

                // How can I get this from Ninject?
                IConfiguration configuration = new JsonConfiguration();
                configuration.Load();
                c.Service<Service>(sc => {
                    sc.ConstructUsingNinject();
                    sc.WhenStarted((service, control) => service.Start(control));
                    sc.WhenStopped((service, control) => service.Stop(control));
                    sc.UseQuartzNinject();
                    sc.ScheduleQuartzJob(q => q.WithJob(() …
Run Code Online (Sandbox Code Playgroud)

c# ninject scheduled-tasks quartz.net topshelf

2
推荐指数
1
解决办法
814
查看次数

使用 Log4net 的简单注入器和日志记录抽象

为了尝试使用 Log4net 获得良好的日志记录抽象,我从这篇 SO 帖子中获取了抽象,并从这篇 SO 帖子中获取了适配器,并尝试让它们一起工作。

真正剩下要做的就是配置容器,而这是我尚未成功完成的部分。

我尝试过的配置是

public static class InfrastructureRegistry
{
    public static void RegisterLoggingServices(this Container container)
    {
        container.RegisterConditional(typeof(ILog), c => LogManager.GetLogger(
            c.Consumer.ImplementationType).GetType(), 
            Lifestyle.Scoped, c => true);
        container.RegisterPerWebRequest<ILogger, Log4netAdapter>();
    }
}
Run Code Online (Sandbox Code Playgroud)

正如您从代码中看到的,我想要一个特定的 log4net 记录器,它从注入的类中获取其类型。虽然大多数日志记录都是以包罗万象的方式完成的,但我希望在较低层中进行一些日志记录,例如当表单验证失败时。

ActivationException通过该配置得到的是:

LogImpl 类型的构造函数包含名称为“logger”且类型为 ILogger 的未注册参数。请确保ILogger已注册,或更改LogImpl的构造函数。

不太确定从这里去哪里,所以任何帮助将不胜感激。

编辑

抱歉,我应该指出,我正在尝试编写它,这样我只需编写此配置一次。以下工厂函数有效,但我不想每次要注入记录器时都手动添加更多配置:

container.RegisterPerWebRequest<ILog>(() => LogManager.GetLogger(typeof(LoginController)));
Run Code Online (Sandbox Code Playgroud)

c# log4net simple-injector

2
推荐指数
1
解决办法
2294
查看次数

将依赖项注入实体框架实体和项目

有没有办法将依赖项注入从EF Linq context.Entities.Select(x => new Y {...})投影返回的对象?(我使用的是Simple Injector,但概念仍然存在)

我试图实现的一些事情:(这只是输入,没有编译,抱歉任何语法错误/不完整)

// person MAY be an entity, but probably more likely a class to serve a purpose
public class Person {
  public string Name
  public DateTime DOB {get;set; }

  // what I want to achieve: note, I don't want to have complex logic in my model, I want to pass this out to a Service to determine.. obviously this example is over simplified...
  // this could be a method or a …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework dependency-injection simple-injector

2
推荐指数
2
解决办法
805
查看次数

使用 Simple Injector 注册集合

我尝试在 c# 中使用简单的注入器注册一个集合。我的方法如下:

container.Collection.Register<IValidateMitarbeiter>(
    typeof(MitarbeiterVerfuegbarkeitValidator),
    typeof(MitarbeiterQualifikationsValidator));
Run Code Online (Sandbox Code Playgroud)

但我收到此错误消息:

配置无效。创建 IDispoLinienManager 类型的实例失败。DispoLinienManager 类型的构造函数包含名称为“mitarbeiterValidators”且类型为 IValidateMitarbeiter 的未注册参数。请确保 IValidateMitarbeiter 已注册,或更改 DispoLinienManager 的构造函数。

这是 DispoLinienManager 的构造函数

public DispoLinienManager(IDataContextFactory dataContextFactory,
        IDispoPlanLinieFactory dispoPlanLinieFactory,
        IValidateMitarbeiter mitarbeiterValidators)
    {
        this.dataContextFactory = dataContextFactory;
        this.dispoPlanLinieFactory = dispoPlanLinieFactory;
        this.mitarbeiterValidators = mitarbeiterValidators;
    }
Run Code Online (Sandbox Code Playgroud)

IValidateMitarbeiter 有两个实现,它们都在 DispoLinienManager 中使用。如果有任何遗漏的信息,我将很乐意帮助您解决我的问题。

c# dependency-injection simple-injector

2
推荐指数
1
解决办法
3388
查看次数

简单的喷射器将具体类型与生活方式结合起来

我正在寻找一种可以使用指定的生活方式注册具体类型的方法,基本上如下所示。

public void SomeFunction( Type concrete, Lifestyle lifestyle ) =>
    container.Register( concrete, lifestyle );
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection simple-injector

2
推荐指数
1
解决办法
2052
查看次数

尚未注册类型 &lt;TYPE&gt; 的服务

我正在开发一个 asp.net 核心 mvc 项目,并尝试将一个数据库对象注入到视图中,以便在视图中从中检索一些东西。

我将该类注入到 startup.cs 中并使用了 @inject,但仍然出现异常。

InvalidOperationException: 没有注册“DbServices.CredentialDb”类型的服务。

Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
Run Code Online (Sandbox Code Playgroud)

这是 Startup.cs ConfigureServices 方法:

Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
Run Code Online (Sandbox Code Playgroud)

这是我添加数据库访问类的地方:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddIdentity<ApplicationUser, IdentityRole>(
        options => options.User.AllowedUserNameCharacters = null)
        .AddEntityFrameworkStores<AppDbContext>();
    services.AddControllersWithViews();
    services.AddDbContextPool<AppDbContext>(
        options => options.UseSqlServer(
            _config.GetConnectionString("AutoLoverDbConnection"), 
            x => x.MigrationsAssembly("AutoMatcherProjectAss"))
        .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
    services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
    services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
    services.AddSingleton<ISessionManager, ClientSIdeSessionManager>();
    services.AddHttpContextAccessor();
    services.AddSession();
    services.Configure<CookiePolicyOptions>(options =>
    {
        // This lambda determines whether user consent for non-essential cookies
        // is needed for a given request.
        options.CheckConsentNeeded = context => …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection asp.net-core razor-pages

2
推荐指数
1
解决办法
2315
查看次数