Git Product home page Git Product logo

Comments (3)

roydukkey avatar roydukkey commented on July 28, 2024

Please forgive me. Dependency injection has come around since I've had any major dotnet projects, so I'm not very familiar with the concept. May ask why this isn't acceptable?

public class CustomerRepository
{
	// public MutationContext<Customer> customerMutationContext { get; set; } // line 3

	// public CustomerRepository(MutationContext<Customer> customerMutationContext) // line 5
	// {
	// 	this.customerMutationContext = customerMutationContext;
	// }

	public void SaveCustomer(Customer cust)
	{
		(new MutationContext(cust)).Mutate();
	}
}

Since line 3 and 5 explicitly define a MutationContext of Customer, why not have the constructor implicitly form that context from the parameter?

from dado.componentmodel.mutations.

VictorioBerra avatar VictorioBerra commented on July 28, 2024

Because "new is glue" and it should be the job of the IoC container to new up the dependencies of a class. Since MutationContext takes an instance of the customer, its not possible for the IoC container to provide it.

In my example, I could mock MutationContext and provide one that did anything I wanted in order to test my project. In your example new MutationContext is forever baked into the code even though its an outside dependency.

Ideally id inject IMutationContext and not MutationContext.

from dado.componentmodel.mutations.

roydukkey avatar roydukkey commented on July 28, 2024

Okay. I see what you're going after. You're welcome to submit a pull request.

from dado.componentmodel.mutations.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.