dependency injection - Choosing lifetime for stateless services -


some service types have pretty clear lifetime requirements. example, if 1 using entityframework in asp.net app, clear dbcontext lifetime should tied request. however, there services "stateless": not store state, , instead forward instructions dependencies. simple case query object:

public class myquery : iquery<somequery, someresponse> {     private readonly irepository<mytable> repository; // injected via constructor     public someresponse query(somequery query) {         return repository.all().where(r => r.field == query.field)                .select(r => new someresponse { field = r.field }).single();     } } 

this particular class has no requirements itself, other imposed dependencies. guidelines should used determine lifetime choose type of object? should 1 use transient lifetime whenever possible? or should 1 have longest lifetime possible? , why?


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -