castle-windsor

Setting the Name property during registration of a component using Castle Windsor IoC container

穿精又带淫゛_ 提交于 2019-12-10 15:53:24
问题 In my application I have a class named Message. There exists a property in the Message class with the name MessageType of type string. The MessageType property is used to alert the application as to what data schema will exist within the instance of the Message class. The Message class derives from an interface named IMessage. As an example let's say we have an instance of the Message class who's MessageType property has the value of "com.business.product.RegisterUser". Each MessageType

Castle Windsor Ms Adaptor Core 2.0 Implementation

我的梦境 提交于 2019-12-10 15:47:03
问题 Could someone expand upon the directions Halil Kalkan (@hikalkan) provided here: https://github.com/volosoft/castle-windsor-ms-adapter ORIGINAL - works using standard Microsoft DI public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(); services.AddMvc(); services.AddApiVersioning(); services.AddDbContextPool<CIDMSContext>(options => options.UseSqlServer("")); services.AddScoped<IBuildingRepository, BuildingRepository>(); services.AddScoped<IComponentRepository,

Castle Windsor ASP.NET MVC 4 and Web API same application. Only if MVC controllers have no dependencies?

℡╲_俬逩灬. 提交于 2019-12-10 14:43:07
问题 This article is a good starting point for doing Web API with Castle Windsor, but what if I create a simple MVC controller? It only works if there is no dependency into the inject. Adding this one, i.e.: public class HomeController : Controller { private readonly IValuesRepository repository; public HomeController(IValuesRepository repository) { this.repository = repository; } public ActionResult Index() { return View(); } } Causes the following error : parameterless constructor defined for

How do I pass in the repository to an authorize attribute in ASP.NET MVC

蹲街弑〆低调 提交于 2019-12-10 13:46:41
问题 I am castle Windsor and it works great for controller constructors in passing in the repository that is being used. private IStoryRepository Repository; public StoryController(IStoryRepository Repository) { this.Repository = Repository; } Now I have an Action that is in the admin area to display the main admin menu. I have used a custom authorisation attribute which will just check that the logged in user is an admin (just an isAdmin flag in the users table) [AdminAuthorize] public

Castle Windsor Fluent Registration - What does Pick() do?

回眸只為那壹抹淺笑 提交于 2019-12-10 13:40:07
问题 When using auto-registration with castle windsor I see people doing things like _container.Register( AllTypes.Pick().FromAssembly(Assembly.GetExecutingAssembly()) .WithService.FirstInterface()); For the life of me I can't figure out what the Pick() method does nor can I find any documentation. Can anyone explain it to me? 回答1: Pick(IEnumerable<Type>) is a synonym for From(IEnumerable<Type>) , i.e. it selects the specified types as registration targets. AllTypes.Pick() is the same as AllTypes

Is there a simple way to register static closures with Castle Windsor?

别等时光非礼了梦想. 提交于 2019-12-10 13:22:35
问题 I've been experimenting with using named delegates instead of single-method interfaces. This has some advantages for code size, as we can go from (some linebreaks removed so as not to overstate the case): public interface IProductSource { IEnumerable<Product> GetProducts(); } public class DataContextProductSource : IProductSource { private readonly DataContext _DataContext; public DataContextProductSource(DataContext dataContext) { if (dataContext == null) throw new ArgumentNullException(

How are components removed with Castle 3.0?

蹲街弑〆低调 提交于 2019-12-10 13:05:20
问题 I have IWindsorContaner which exists for the whole application lifetime. For Unittests it is possible to register mocks/stubs, etc. under their Type. When the test is finished and the fixture is disposed the registered components in forthe test are remove with a self created method called "Unregister". Now, I want to update to the latest Castle version which is 3.0. According to the 3.0 release notes something like public void Unregister(string contextName, string registrationName) {

CastleWindsor 3.0 and DefaultServiceHostFactory.RegisterContainer()?

感情迁移 提交于 2019-12-10 12:44:44
问题 The following does not compile: DefaultServiceHostFactory.RegisterContainer(Container.Kernel); The static method does not seem to exist in Castle 3.0 - I checked the breakingchanges.txt and did not see this listed. What am I missing? 回答1: You don't need the call any more as it gets registered when you wire up the facility. container.AddFacility<WcfFacility>(); Is all you need, sweet :) This is not required: DefaultServiceHostFactory.RegisterContainer(Container.Kernel); nor is this Container

How to register same class twice with different dependencies

人盡茶涼 提交于 2019-12-10 12:30:32
问题 I would like to configure Castle Windsor to create two components of same type (Foo -> IFoo), but with different constructor inputs. I would also later like to consume both components when creating another component (type Bar - see code below). public interface IFoo { } public class Foo : IFoo { private string _prop; public Foo(string prop) { _prop = prop; } } public class Bar { private IFoo _fooAbc; private IFoo _foo123; public Bar(IFoo fooAbc, IFoo foo123) { _foo123 = foo123; _fooAbc =

creating WindsorContainer results in type conversion error

放肆的年华 提交于 2019-12-10 12:18:42
问题 I am trying to following book : Pro ASP.NET MVC Framework by Steven Sanderson... The line container = new WindsorContainer(xi); produces this error: Could not convert from 'DomainModel.Abstract.IPeopleRepository, DomainModel' to System.Type - Maybe type could not be found** public WindsorControllerFactory() { ConfigResource confres = new ConfigResource("castle"); XmlInterpreter xi = new XmlInterpreter(confres); container = new WindsorContainer(xi); // Also register all the controller types as