Example #1
0
        public static IServiceCollection UseInjector(this IServiceCollection services,
                                                     Action <InyectorConfiguration> configurationAction)
        {
            // Call Inyector Startup
            InyectorStartup.Init((c) =>
            {
                // add default modes
                c.AddMode(AspNetCoreModeFactory.Create(ServiceLifetime.Scoped, services))
                .AddMode(AspNetCoreModeFactory.Create(ServiceLifetime.Singleton, services))
                .AddMode(AspNetCoreModeFactory.Create(ServiceLifetime.Transient, services));

                configurationAction.Invoke(c);
            });

            return(services);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            InyectorStartup.Init(c =>
            {
                c.DefaultMode((type, interf) => services.AddSingleton(interf, type));
                c.AddMode("MyCustomMode", (type, interf) => services.AddScoped(interf, type));

                //c.Scan(typeof(Startup).Assembly)
                //    .AddRuleForNamingConvention((type, interf) => services.AddSingleton(interf, type));

                c.Scan(typeof(Startup).Assembly)
                .AddRuleForNamingConvention(Mode.DefaultMode)
                .AddRuleForEndsWithNamingConvention(new[] { "Helper", "Services", "Foo" }, "MyCustomMode");
            });
        }