Hi there,
I just recently read about "Mocking objects" for unit testing and currently I'm having a difficulties implementing this approach in my application. Please let me explain my problem.
I have a User model class, which is dependent on 2 data sources (database and facebook web service). The controller class simply use this User mo...
I have an object that loads an instance of another object in a method.
$survey = new survey;
$question = new question($survey);
$question->load($question_id);
class question {
public function __construct(&$survey)
{
$this->survey = $survey;
}
public function load ($id)
{
// now a question is loaded
// want t...
This is an extension of this question: http://stackoverflow.com/questions/3027082/understanding-how-to-inject-object-dependencies. Since it is a bit different, I wanted to separate them, to make it, hopefully, easier to answer. Also, this is not a real system, just a simplified example that I thought we'd all be familiar with. TIA. :
...
The way I understand it, DI allows you to use an IoC container to do something like
If a constructor needs an IFoo, use a concrete class Foo : IFoo.
But how is a Mock object using Moq different? Doesn't it also use DI to create a fake Foo?
Thanks.
...
Consider this code snippet:
public static class ApplicationContext
{
private static Func<TService> Uninitialized<TService>()
{
throw new InvalidOperationException();
}
public static Func<IAuthenticationProvider> AuthenticationProvider = Uninitialized<IAuthenticationProvider>();
public static Func<IUnitOfWork...
I'm playing with DI (using Unity). I've learned how to do Constructor and Property injection. I have a static container exposed through a property in my Global.asax file (MvcApplication class).
I have a need for a number of different objects in my Controller. It doesn't seem right to inject these throught the constructor, partly because...
This is driving me nuts...
Two assemblies/projects in play:
An Infrastructure project, which has an interface in it:
IDtoMapping<in TDto, out TDomain>
And an app project, referencing Infx, with an implementation:
PatientMapping : IPatientMapping
...and a marker interface, just to be clear:
public interface IPatientMappin...
I have noticed from several web pages that apparently Spring 3.0 supports @Inject from JSR-330. As we would really like to use JSR-299 syntax for dependency injection in our libraries for both web apps and stand-alone applications, and have alternatives to Weld, it would be nice if Spring could do this.
Being a novice to Spring, I trie...
Hi,
I would like of inject a wrapper of my sessionfactory in my wcf service, but my service is in other server and I want set nhibernate in my site asp.net.
I have a interface as:
public interface ISessionBuilder
{
ISession Current{get;};
void Close();
}
public class SessionBuilder : ISessionBuilder
{
static SessionBuilder()
...
What I am looking is something similar to the below (http://github.com/ninject/ninject.web.mvc):
README.markdown
This extension allows integration between the Ninject core and ASP.NET MVC projects. To use it, just make your HttpApplication (typically in Global.asax.cs) extend NinjectHttpApplication:
public class YourWebApplication ...
Hi, I am trying to get started with some simple dependency injection using C# and i've run up against an issue that I can't seem to come up with an answer for.
I have a class that was written by another department for which I don't have the source in my project. I wanted to inject an object of this type though a constructor using an int...
I'm working on a large legacy application using stateless session beans that has recently been migrated from EJB2 to EJB3, and I'd like to use dependency injection. Unfortunately, in a (IMO misguided) attempt to achieve decoupling, all actual business logic lies in "manager" classes to which the session beans forward their calls. Those m...
AppContext.xml
<bean id="myBean" class="com.myapp.MyClass">
<property ref="myService"/>
</bean>
MyService.java
@Service
public class MyService {
...
}
This will throw an exception stating that no bean can be found for property "myService", which I understand because it can't be found in the context files, but I can autowire th...
I've recently discovered a possible candidate for dependency injection in a .Net application I've designed.
Due to a recent organizational policy, it is no longer possible to call smtp mail services from client machines on our network. So I'm going to have to refactor all the code in my application where it was previously calling the s...
I have written a generic type: IDirectorySource<T> where T : IDirectoryEntry, which I'm using to manage Active Directory entries through my interfaces objects: IGroup, IOrganizationalUnit, IUser.
So that I can write the following:
IDirectorySource<IGroup> groups = new DirectorySource<IGroup>(); // Where IGroup implements `IDirectoryEnt...
I'm not sure for which use cases one should to use DI in the application. I know that injecting services like PlaceService or CalculationService etc fits very well but should I also create my domain objects with DI like a User? What is if the User has only one constructor which requires a first and lastname. Is this solveable with DI?
S...
Spring framework is NON - INTRUSIVE.
Can you please elaborate this?
Thank You :)
...
Hi,
I'm trying to use Scala as part of an existing Java application and now I run into an issue with dependencies injected with a setter method (no DI frameworks in this part of code). How is this handled in a Scala way?
In Scala both val and var require to be initialized when declared but I can't do that, since the Java setters injec...
Hi,
Is there a way in Spring to get an object programatically as if it was injected by the xml file.
Here is what i mean
I have this class called securityDelegate. It's instances are always created by spring
<bean id="securityDelegate" class="securityBusinessDelegate" lazy-init="true">
<property name="securityServiceEJB" ref="sec...
Does anybody have an example of how to use Google Guice to inject properties from a .properties file. I was told Guice was able to validate that all needed properties exist when the injector starts up.
At this time I cannot find anything on the guice wiki about this.
...