c# - To Constructor Inject Or Not With TDD? -
I have a method that I'm trying to test the unit using a query object, I type this query object I would like to stub my unit tests for this query object in a dependency (unitofwork) I'm using IOC / DI container to instantaneously my items in the app, however I do not use container while doing TDD I like the way I look at it, I have 2 choices:
- Add a query object to the query object as a field or property, and it's the CTOR argument Inject in form. Although it does not seem right that this 1 method is the only method that will use it, and if I ever need to add another method that used this query object, then the object
- Add the query object to the signature of the method. odor?
Is there any other option or petter for this? Or am I doing it wrong?
Here are some pseudo codes:
Option # 1
Public Class Order Controller {Public Order Controller (IORDCF Query) {This.query = Query; } Private Readonly IOrderQuery query; Public quiz & lt; Order & gt; Ordering () {var results = query (...); ...}}
option # 2
public order order controller {public Q & A; Order & gt; Order whitening (IOrderQuery query) {var results = query (...); ...}}
and my query object
public class OrderQuery: IOrderQuery {public order (IUnitOfWork unitOfWork) {...}}
If I ever want to add another method that uses this query object
If this prevents you from using constructor injection, consider taking a IOrderQueryFactory
injection. instead of this.
Comments
Post a Comment