ASP.NET 5 dependency injection, inject with parameters -


i'm using vnext implementation of di. how pass parameters constructor? example, have class:

public class rediscacheprovider : icacheprovider {     private readonly string _connectionstring;      public rediscacheprovider(string connectionstring)     {         _connectionstring = connectionstring;     }     //interface methods implementation... } 

and service register:

services.addsingleton<icacheprovider, rediscacheprovider>(); 

how pass parameter constructor of rediscacheprovider class? example autofac:

builder.registertype<rediscacheprovider>()        .as<icacheprovider>()        .withparameter("connectionstring", "myprettylocalhost:6379"); 

you can either provide delegate manually instantiate cache provider or directly provide instance:

services.addsingleton<icacheprovider>(provider => new rediscacheprovider("myprettylocalhost:6379"));  services.addinstance<icacheprovider>(new rediscacheprovider("myprettylocalhost:6379")); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -