本文整理汇总了C#中Ninject.StandardKernel.Inject方法的典型用法代码示例。如果您正苦于以下问题:C# StandardKernel.Inject方法的具体用法?C# StandardKernel.Inject怎么用?C# StandardKernel.Inject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ninject.StandardKernel
的用法示例。
在下文中一共展示了StandardKernel.Inject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomIdentity
public CustomIdentity(FormsAuthenticationTicket ticket)
{
_ticket = ticket;
var kernel = new StandardKernel();
AccountRepository = new AccountRepository();
kernel.Inject(AccountRepository);
}
示例2: SetUp
public virtual void SetUp()
{
NinjectSettings settings = new NinjectSettings()
{
InjectNonPublic = true
};
IKernel kernel = new StandardKernel(settings, new CoreBindingModule(), new DataAccessBindingModule());
kernel.Inject(this);
}
示例3: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
DependencyResolver.SetResolver(new NinjectDependencyResolver());
var _kernel = new StandardKernel(new CoreInjectionModule());
_kernel.Inject(Membership.Provider);
}
示例4: CanResolveDependenciesOnExistingObject
public void CanResolveDependenciesOnExistingObject()
{
var kernel = new StandardKernel();
kernel.Bind<IWeapon>().To<Lightsaber>();
var darth = new SithLord();
darth.Weapon.ShouldBeNull();
kernel.Inject(darth);
darth.Weapon.ShouldBeInstanceOf<Lightsaber>();
}
示例5: CanResolveDependenciesOnExistingObject
public void CanResolveDependenciesOnExistingObject()
{
var kernel = new StandardKernel();
kernel.Bind<IWeapon>().To<Lightsaber>();
var darth = new SithLord();
Assert.That(darth.Weapon, Is.Null);
kernel.Inject(darth);
Assert.That(darth.Weapon, Is.InstanceOf<Lightsaber>());
}
示例6: Deve_resolver_dependencias_manualmente
public void Deve_resolver_dependencias_manualmente()
{
IKernel kernel = new StandardKernel(new Modulo());
// A instância normal não tem as dependências resolvidas;
var servico = new Servico();
Assert.IsNull(servico.Fornecedor);
// O método Inject resolve as dependências da instância usando como marcador o atributo [Inject];
kernel.Inject(servico);
Assert.IsNotNull(servico.Fornecedor);
Assert.IsInstanceOfType(servico.Fornecedor, typeof(Fornecedor));
}
示例7: BuildUp
static void BuildUp()
{
Console.Write("Straight:\t");
watch.Start();
for(int i = 0; i < n; ++i) {
var c = new TestClass5();
c.t = new TestClass1();
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
watch.Reset();
Console.Write("pooDI:\t\t");
watch.Start();
var pooDI = new DI.Container();
pooDI.RegisterType<ITestClass1, TestClass1>(false);
for(int i = 0; i < n; ++i) {
var c = new TestClass5();
pooDI.BuildUp<TestClass5>(c);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
watch.Reset();
Console.Write("Unity:\t\t");
watch.Start();
var unity = new UnityContainer();
unity.RegisterType<ITestClass1, TestClass1>();
for(int i = 0; i < n; ++i) {
var c = new TestClass5();
unity.BuildUp<TestClass5>(c);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
watch.Reset();
Console.Write("Ninject:\t");
watch.Start();
var kernel = new StandardKernel();
kernel.Bind<ITestClass1>().To<TestClass1>();
for(int i = 0; i < n; ++i) {
var c = new TestClass5();
kernel.Inject(c);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
watch.Reset();
Console.Write("Autofac:\t");
watch.Start();
var builder = new ContainerBuilder();
builder.RegisterType<TestClass1>().As<ITestClass1>();
var container = builder.Build();
for(int i = 0; i < n; ++i) {
var c = new TestClass5();
container.InjectProperties<TestClass5>(c);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
watch.Reset();
Console.WriteLine("Castle Windsor:\tNot supported");
}
示例8: Initialize
public void Initialize()
{
IKernel kernel = new StandardKernel(this.GetInstanceDIControllersModule());
kernel.Settings.ActivationCacheDisabled = false;
kernel.Inject(this);
}
示例9: InitialiseAdapter
internal void InitialiseAdapter()
{
_logger.Info("Requesting Adapter Start");
if (PlatformConnector == null)
{
_logger.Fatal("Plugin could not be found. Ensure that plugin is copied in folder and restart the service");
return;
}
List<INinjectModule> modules = new List<INinjectModule> { new BootStrapper() };
if (PluginBootstrapper != null)
{
_logger.InfoFormat("Plugin Bootstrapper found of type={0}", PluginBootstrapper.GetType().Name);
modules.AddRange(PluginBootstrapper.BootstrapModules);
}
StandardKernel iocContainer = new StandardKernel(modules.ToArray());
var settings = iocContainer.Get<ISettings>();
var service = iocContainer.Get<IServiceFacade>();
var streamListenerManager = iocContainer.Get<IStreamListenerManager>();
iocContainer.Settings.InjectNonPublic = true;
//needed for Plugin properties since plugin is not instantiated by Ninject
iocContainer.Inject(PlatformConnector);
_adapter = new Adapter(settings, service, PlatformConnector, streamListenerManager);
if (settings.UseSupervisor)
{
// SS.Integration.Diagnostics.RestService uses Owin.HttpListeners.
// that assembly must be referenced in the startup project even if not
// directly used, so do not remove it from the list of references
_supervisor = iocContainer.Get<ISupervisor>();
if (_supervisor == null)
{
_logger.Error("Cannot instantiate Supervisor as not suitable module was found");
}
else
{
_logger.Info("Initializing adapter's supervisor");
try
{
_supervisor.Initialise();
}
catch (Exception e)
{
_logger.Error("An error occured during the initialization of the adapter's supervisor. The supervisor will not be available", e);
}
}
}
_adapter.Start();
_logger.Info("Adapter has started");
}