Questions tagged [ninject]
15 questions
21
votes
7 answers
What is the "right" way to implement DI in .NET?
I'm looking to implement dependency injection in a relatively large application but have no experience in it. I studied the concept and a few implementations of IoC and dependency injectors available, like Unity and Ninject. However, there is one…

user3223738
- 459
- 1
- 4
- 6
5
votes
4 answers
Does anyone have a good DI registration pattern?
I've done this so many times but I never end up liking how my code turns out. I'm asking if anyone else has the same problems and can offer solutions or conventions that they've used to make cleaner code.
When I build a C# service, I get TopShelf,…

Frank Bryce
- 938
- 1
- 6
- 15
4
votes
1 answer
Configuring DI in a decoupled app
I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is escaping me.
If the application's architecture is like [DAL] => [BLL] <= [UI], with the Business Logic Layer free of dependencies upon Data…

Mathieu Guindon
- 1,720
- 16
- 33
3
votes
0 answers
Manual dependency injection or abstract factory
We're starting to use dependency injection in a fairly large, interactive program. It's early yet, but I have a feeling that the majority of the objects being injected are going to want runtime data passed in to their constructors. Prior to this,…

donkey
- 139
- 2
2
votes
2 answers
Unit of work + repository pattern + dependency injection
I am in the process of refactoring and improving a codebase. One of the major missing features is transactional safety and certain errors arising from each repository having its own DbContext.
The current setup is as follows:
The BLL (FooManager)…

Flater
- 44,596
- 8
- 88
- 122
2
votes
1 answer
Using ninject in a class library
Looking for some help getting my head around ninject and DI.
Using the simple examples I've found online everything works nicely but trying to do something more complex is causing headaches.
I have a class library that receives files, analyses them…

Flick
- 23
- 1
- 3
1
vote
2 answers
Add behaviours without changing existing code
I have a data access layer, which currently communicates with a database.
public interface IDao // T is my DTO
{
Write(IEnumerable dtosToPersist)
}
public class Dao : IDao
{
private readonly IBulkCopySaver _bulkSaver;
…

Baguette
- 27
- 2
1
vote
1 answer
Manually disposing Entity Framework Context while using Ninject InRequestScope();
Spending some time sifting through documentation, I'm trying to figure out the best software architecture with or without the dispose pattern.
I've built the Repository pattern many time over the years, whilst using the dispose pattern which…

Tez Wingfield
- 253
- 2
- 12
1
vote
1 answer
Ninject/DI: How to correctly pass initialisation data to injected type at runtime
I have the following two classes:
public class StoreService : IStoreService
{
private IEmailService _emailService;
public StoreService(IEmailService emailService)
{
_emailService = emailService;
}
}
public class…

MrLane
- 629
- 5
- 14
1
vote
1 answer
How can I bind an interface to a class decided by an xml or database configuration at the launch of the application?
I'm re-working on the design of an existing application which is build using WebForms. Currently the plan is to work it into a MVP pattern application while using Ninject as the IoC container.
The reason for Ninject to be there is that the boss had…

ipohfly
- 271
- 1
- 3
- 8
0
votes
1 answer
Dependency injection multiple instances or only one InrequestScope
I'm trying to understand what happens with dependencies (Ninject) when a same Interface in injected in multiple classes. I am specifying InRequestScope for my bindings so as I understand there should always be a single instance of let's say my…

Iztoksson
- 197
- 1
- 4
- 11
0
votes
1 answer
What is a good practical example demonstrating an architectural advantage in interface dependency injection
I need help (preferably by way of a practical example) to understand why/if the following implementation of IoC/DI (in this case using Ninject) provides an architectural advantage:
using (IKernel kernel = new StandardKernel())
{
…

Chris Halcrow
- 401
- 2
- 6
- 14
0
votes
1 answer
How to apply IoC (or something similar) to a constant?
I have the following class with the following members:
public class RegistrationPresenter : EPiPresenter, IDisposable
{
private readonly static string[] DefaultUserRoles = { AppRoles.RegisteredRole,…

David Jiménez Martínez
- 604
- 6
- 16
0
votes
1 answer
How to make Ninject inject an MVC view model?
How do I configure Ninject so it injects an instance in a view model?
PS. It is an abstracted service to help with validation, so I am not trying to burden the model with too much responsibilities.

Boris Yankov
- 3,573
- 1
- 23
- 29
-1
votes
1 answer
Dependency injection - passing domain objects to underlying dependencies with NInject
I'm working on a larger project. I hope I understood DI well and based-on that I'm able to do this:
// domain object holding configuration ata
var input = new GeneratorInput
{
Constructions = new List(),
InitialConfiguration =…

Patrik Bak
- 277
- 1
- 7