草庐IT

property-injection

全部标签

c# - StructureMap 无法使用注入(inject)实例进行 setter 注入(inject)

我在将实例注入(inject)结构图中进行测试时遇到问题。我的对象图看起来像这样internalclassConfigurationManager:IConfigurationManager:IManager{publicISomeManagerSomeManager{get;set;}}internalclassSomeManager:ISomeManager:IManager{publicIConfigurationManagerConfigurationManager{get;set;}}1)首先我创建容器并添加所有找到的注册表_container=newContainer(c=

c# - EF 6 的工作单元和依赖注入(inject)设计问题

我使用EntityFramework6开发Web应用程序,在设计应用程序结构时遇到困难。我的主要问题是如何在我的特定情况下处理依赖项注入(inject)。下面的代码是我希望应用程序的样子。我正在使用Autofac,但我想它对每个DI用户来说都足够基本了:publicinterfaceIUnitOfWork{boolCommit();}publicclassUnitOfWork:IUnitOfWork,IDisposable{privateDbContext_context;publicUnitOfWork(DbContextcontext){_context=context;}publ

c# - 使用 CaSTLe Windsor 将依赖项注入(inject) CustomAttribute

在我的ASP.NetMVC应用程序中,我实现了自定义ActionFilter来授权用户。我使用CaSTLeWindsor为所有Controller提供依赖注入(inject),如下所示:protectedvirtualIWindsorContainerInitializeServiceLocator(){IWindsorContainercontainer=newWindsorContainer();ControllerBuilder.Current.SetControllerFactory(newWindsorControllerFactory(container));contain

C# WPF 附加属性 - 错误 : "The property does not exist in XML namespace"

我需要为现有的WPF控件(组框、文本框、复选框等)创建一个新属性,该属性将存储其访问级别,因此我找到了附加属性。我以这个网站为例http://dotnetbyexample.blogspot.com.br/2010/05/attached-dependency-properties-for.html一切都很好,但是当我尝试在某些控件上使用它时出现以下错误...Error1Theproperty'DependencyPropertiesHoster.AcessLevel'doesnotexistinXMLnamespace'clr-namespace:ImageGUI.App_Code;

c# - Properties.Settings.Default.Save(); ->那个文件在哪里

我有一个使用“设置”的应用。要保存我使用的设置:Properties.Settings.Default.Save();阅读我使用的:Properties.Settings.Default.MyCustomSetting;在我的应用程序文件夹中,我只有exe文件。没有配置文件。我的应用程序运行良好,可以读写设置。如果该文件不在应用程序文件夹中,该文件位于何处? 最佳答案 在我的WindowsXP机器上,设置保存在C:\DocumentsandSettings\\ApplicationData\下某处名为user.config的文件中。

c# - EF4 代码优先 : how to add a relationship without adding a navigation property

我应该如何在不使用任何导航属性的情况下使用CodeFirst来定义关系?之前,我通过在关系的两端使用导航属性来定义一对多和多对多。并在数据库中创建适当的关系。这是类外观的精简版本(为简单起见,我已将多对多关系转换为一对多)。publicclassUser{publicstringUserId{get;set;}publicstringPasswordHash{get;set;}publicboolIsDisabled{get;set;}publicDateTimeAccessExpiryDate{get;set;}publicboolMustChangePassword{get;set

c# - 有没有理由拥有没有 setter/getter 的属性(property)?

我的经理问我使用带有setter而没有getter的属性是否是好的做法。publicclassPropertyWrapper{privateMyClass_field;publicMyClassProperty{set{_field=value;}}publicstringFirstProperty{get{return_field.FirstProperty;}}publicstringSecondProperty{get{return_field.SecondProperty;}}}他将使用其他属性来公开私有(private)字段中的属性,由该setter设置。我的建议是只使用私有

c# - 将 DbContext 注入(inject)服务层

我应该如何将我的MyDbContext注入(inject)到我的数据库服务层MyService中?Startup.cspublicvoidConfigureServices(IServiceCollectionservices){services.AddDbContext(options=>options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));services.AddMvc();}MyDbContext.cspublicpartialclassMyDbContext:DbContext{p

c# - ASP.NET Core 2 中多个相同类型实例的依赖注入(inject)

在ASP.NETCore2WebApi中,我想使用依赖注入(inject)来注入(inject)httpClientAHttpClient的实例至ControllerA,和一个实例httpClientB的HttpClient至ControllerB.DI注册代码如下所示:HttpClienthttpClientA=newHttpClient();httpClientA.BaseAddress=endPointA;services.AddSingleton(httpClientA);HttpClienthttpClientB=newHttpClient();httpClientB.Bas

c# - 在 WPF 中获取 "<Property Name> was already registered by "<控件名称>"错误

我在WPF中有一个用户控件,它绑定(bind)到一个依赖属性。当我尝试编译应用程序时,出现“属性名称”已由“控件名称”注册的错误,设计器显示“无法创建“用户控件”的实例”错误。这是我的简单控件的样子:ExampleUserControl.xaml:ExampleUserControl.xaml.cs:publicpartialclassExampleUserControl:UserControl{publicDependencyPropertySomeStringValueProperty=DependencyProperty.Register("SomeStringValue",ty