Open dadhi opened 4 years ago
Reference doc: https://github.com/ninject/Ninject/wiki/Modules-and-the-Kernel#modules
Ninject example:
public class WarriorModule: NinjectModule
{
public override void Load()
{
Bind<IWeapon>().To<Sword>();
Bind<Samurai>().ToSelf().InSingletonScope();
}
}
A similar DryIocModule may be approached like this:
public abstract class DryIocModule
{
public IRegistrator R { get; set };
public abstract void Load();
}
public class WarriorModule: DryIocModule
{
public override void Load()
{
R.Register<IWeapon, Sword>();
R.Register<Samurai>(Reuse.Singleton);
}
}
// Registering the modules. You may provide the assemblies instead of implementation types.
container.RegisterMany(
implTypes: new[] { typeof(WarriorModule, /* others */ ) }
made: PropertiesAndFields.Of.Name(nameof(DryIocModule.R)));
I wish to replace my NInject configuration. Can I try DryIocModule for size or do I have to wait for a future release ?
You may do it know. Even better if you have some problems I may help with improvements, or at least track this here for documentation and future improvements.
I can't find this package even among pre-releases in Nuget.
Huh, it is not ready yet (I am just starting). I mean that you can grab the code from example and start experimenting with it and I may help with questions, etc.
No stress. Thanks for offering your help. Please estimate your package release plan and I will test it.
Hello @dadhi
4.7 is the one shipping this?
No, there is no specific ETA yet. I am using the Ninject on my production project, so I am still planning to work on this.
I need some help/suggestions on how can i make migrate from Ninject which is used in my project to DryIOC for Dotnet Framework. I tried but unable to handle Kernel part. @dadhi @sigmarsson @wjrogers
@jainashish1711
What's your setup or the example code?
Please find sample Startup.cs class below
public partial class Startup { public static HttpConfiguration HttpConfiguration; public void Configuration(IAppBuilder app) { app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
var kernel = CreateNinjectKernel();
app.UseNinjectMiddleware(() => kernel);
app.UseOwinExceptionHandler();
ConfigureAuth(app, kernel);
ConfigureWebApi(app);
GlobalConfiguration.Configuration.Formatters
.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}
public IKernel CreateNinjectKernel()
{
return new StandardKernel(
NinjectBaseDomainModule.Instance,
new NinjectDISDomainModule(),
new NinjectBaseRepositoryModule(),
new NinjectDISRepositoryModule(),
new NinjectWebModule());
}
private static void ConfigureWebApi(IAppBuilder app)
{
HttpConfiguration = new HttpConfiguration();
WebApiConfig.Register(HttpConfiguration);
app.UseNinjectWebApi(HttpConfiguration);
}
}
Also having trouble binding for these type of codes:
Bind
@dadhi
Here there is a lot of things to digest because you're using Web extensions.
I won't answer it right away, maybe I look later into it when I need to convert my own project. Or you may dig it yourself, and asking some concrete questions when you stuck.
Regarding WhenInjectedInto
...
The example may be translated like this:
Ninject:
Bind<IInterface>().To<ClassA>()
.WhenInjectedInto<ClassB>();
DryIoc:
container.Register<IInterface, ClassA>(
setup: Setup.With(condition: r => r.Parent.ImplementationType == typeof(ClassB)));
Hello @dadhi , has it bogged down, cancelled or just starving of human resource ? Will you introduce modules as NInjectModule
works, so that IoC configurations could be reusable ?
@sigmarsson
Yes, now it is time/hr needed. Plus to start things up I would love to see a sample project or tests with minimal useful set of Ninject API.
I had a big project myself before, but no longer have it now. And eating a big elephant is harder than a small rabbit..
Still I am poking random people in Ninject issues what features do they like and using, etc. Almost no life is there :(
@dadhi , Then let them go. Maybe DryIoc could just copy the entire NinjectModule concept as you drew up earlier;
public class WarriorModule: DryIocModule
{
public override void Load()
{
R.Register<IWeapon, Sword>();
R.Register<Samurai>(Reuse.Singleton);
}
}
What is registered in this method, is so appearing in the Kernel into which the respective module will be injected. No magic, just it shall provide a single purpose; reuse the configuration.
@dadhi is it yet on your road map ?
Open question. I am currently not working with NInject myself. So it is hard to get with MVP number of features and the examples to convert. So any help here is appreciated.
Faster drop-in Ninject replacement keeping the API surface intact on top of the DryIoc implementation.
Similar to the DryIoc.Syntax.Autofac.