我想使用的綁定設在這裏的方法,但有沒有運氣 https://github.com/ninject/ninject.extensions.factory/wiki/Factory-interface https://github.com/ninject/ninject.extensions.factory/wiki/Factory-interface%3A-Referencing-Named-BindingsNinject工廠沒有與公約工作對我來說
請記住,我不是想這樣來做:https://gist.github.com/akimboyko/4593576 相反我試圖使用慣例GetMercedes()意味着
我基本上試圖達到這個:https://gist.github.com/akimboyko/4593576與上述例子中指定的約定。
using Ninject;
using Ninject.Extensions.Factory;
using Ninject.Modules;
using Ninject.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Test.NinjectFactory
{
public class Program
{
public static void Main()
{
using (var kernel = new StandardKernel(new CarModule()))
{
var factory = kernel.Get<ICarFactory>();
var mercedes =factory.GetMercedes();
int i = 1;
}
}
public interface ICar
{
void Drive();
}
public class Mercedes : ICar
{
readonly ICarFactory carFactory;
public Mercedes(ICarFactory carFactory)
{
this.carFactory = carFactory;
}
public void Drive()
{
var Mercedes = this.carFactory.GetMercedes();
}
}
public interface ICarFactory
{
ICar GetMercedes();
}
public class CarModule : NinjectModule
{
public override void Load()
{
//https://github.com/ninject/ninject.extensions.factory/wiki/Factory-interface%3A-Referencing-Named-Bindings
Kernel.Bind<ICarFactory>().ToFactory();
Bind<ICar>().To<Mercedes>().NamedLikeFactoryMethod<ICarFactory>(x => x.GetMercedes());//doesnt work for me
}
}
}
}
目標護理是使用慣例,像這樣:HTTPS://github.com /ninject/ninject.extensions.factory/wiki/Factory-interface%3A-Referencing-Named-Bindings 因此,建議可能不是我所期待的。感謝您花時間回覆。 – hidden