inversion-of-control

Logging as a decorator vs. Dependency Injection - what if I need to log inside the class?

爱⌒轻易说出口 提交于 2019-12-04 16:11:10
问题 (I originally asked this question in this comment, but Mark Seemann asked me to create a new question instead.) I'm starting a new app (.NET Core, if that matters), and right now I'm trying to decide how exactly to do logging. The general consensus seems to be that logging is a cross-cutting concern, so the logger shouldn't be injected directly into the class that is supposed to log. Often, there's an example like the following class how not to do it: public class BadExample : IExample {

Unable to resolve a controller that was loaded from external dll

走远了吗. 提交于 2019-12-04 15:51:42
问题 I am building a Web API using MVC4 Web API with an IoC container (Simple Injector in this case, but I don't think this problem is related to that container) that should expose a variety of CRUD and query operations. The reason for using IOC in my case is that we are a dev shop and I need to be able to let customers build their own web API controllers to expose the data they need to expose need from our system. Consequently, I was hoping to design my solution in a way that allowed me to

Learning Inversion of Control through Dependency Injection in MVC 3

巧了我就是萌 提交于 2019-12-04 15:45:15
Can someone please provide me a simple example of DI and IoC ? I understand the first one but was unable to get an implementation of the second one. I'm working with MVC 3 and I really want to use the IDependencyResolver , but I can't understand how. Is ninject an option or is it required? Is there a tutorial like nerdDinner and I wasn't able to find it? Can somebody give me a link to study it? Ruben Bartelink In order to grok real world DI and its patterns and anti-patterns quickly, I recommend getting DI in .NET . (I've ordered it already EDIT: And it was a page turner that taught me a lot

Custom principal in ASP.NET MVC

做~自己de王妃 提交于 2019-12-04 13:45:48
I want to be able to access custom properties for an authenticated user like UserId and FirstName without querying the database each time. I found this site through a post on Stack Overflow and I like the approach - but I use IoC / repositories and decided not to try and get global.asax to communicate with the database for fear that it would be incompatible with the repository pattern. Instead, I created an interface to CustomPrincipal and I use IoC (Castle) to create an instance and pass it to the controllers (and subsequently to my base controller). The base controller uses methods I created

Using Ninject 2.0 with ASP .Net 3.5

╄→尐↘猪︶ㄣ 提交于 2019-12-04 13:07:12
I am trying to use Ninject 2.0 with Asp .Net 3.5 web application. Following are the DLLS and it's versions I am using. Ninject.dll - v2.0.0.0 Ninject.Extensions.Logging.dll v2.0.0.0 Ninject.Web.dll v1.0.0.0 In my global.ascx.cs I have following method. protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(); kernel.Bind<IDataAccess>().To<DataAccessEntBlock>().InSingletonScope(); return kernel; } When I run the application I get following error. Error activating ILoggerFactory No matching bindings are available, and the type is not self-bindable. Activation path: 1)

Dependency Inversion Principle and where to put the interfaces

不打扰是莪最后的温柔 提交于 2019-12-04 12:49:53
I am building a simple MVC application in asp.net. I want to follow the dependency inversion principle and I don't know if I am doing it right. I am currently working on the Authentication system. I have an AccountController which uses the Authenticator service inside. The Authenticator service is injected into the controller by constructor injection. public class AccountController : Controller { private IAuthenticator _authenticator; public AccountController(IAuthenticator authenticator) { _authenticator = authenticator; } // // POST: /Account/Login [HttpPost] public ActionResult Login

Castle Windsor problem

*爱你&永不变心* 提交于 2019-12-04 12:06:26
I have a problem with castle core, i'm trying to inject two different database connection to specific repositories. public class Repository1 { public Repository1(System.Data.Common.DbConnection conn) { } } public class Repository2 { public Repository2(System.Data.Common.DbConnection conn) { } } Now for example im would like to inject Mysql connection to Repository1 and Oracle connection to repository2. Something like this: container.Register(Component .For<DbConnection>() .ImplementedBy<MysqlConnection>() .Named("mysql")); container.Register(Component .For<DbConnection>() .ImplementedBy

Injecting Dependencies into Domain Model classes with Nhibernate (ASP.NET MVC + IOC)

时光总嘲笑我的痴心妄想 提交于 2019-12-04 11:42:58
问题 I'm building an ASP.NET MVC application that uses a DDD (Domain Driven Design) approach with database access handled by NHibernate. I have domain model class (Administrator) that I want to inject a dependency into via an IOC Container such as Castle Windsor, something like this: public class Administrator { public virtual int Id { get; set; } //.. snip ..// public virtual string HashedPassword { get; protected set; } public void SetPassword(string plainTextPassword) { IHashingService hasher =

Which IoC continer to use in cross-platform (Xamarin) applications? [closed]

喜夏-厌秋 提交于 2019-12-04 11:39:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm building a cross-platform application for Windows, OSX, iOS, Windows Mobile, Android and web in ASP.NET. For every client I use C# (I'm using Xamarin). Everything in single VS solution. My core code (domain) is in Class Library (portable) , so it can be used in every UI (Client). I want to use IoC container

MassTransit and Simple Injector [closed]

六眼飞鱼酱① 提交于 2019-12-04 11:22:11
I'm reviewing the MassTransit Distributed Application Framework for .NET . According to the website MassTransit has been built from the beginning with the concept of an IoC container being involved and provides support libraries for a handful of the more "mainstream" IoC Containers. There are (currently) NuGet packages available for Autofac, StructureMap, Castle Windsor, Ninject & Unity. I have selected Simple Injector as my IoC container of choice for performance reasons but I am unable to find an integration library adding support for Simple Injector to MassTransit. Has anyone tried this,