草庐IT

create_default_context

全部标签

c# - 统一: Change default lifetime manager for implicit registrations and/or disable them

Unity容器将自动解析它可以自行识别的任何类型,无需手动注册。这在某些方面很好,但我遇到的问题是它使用TransientLifetimeManager来解决这种类型的问题,而我几乎总是想要一个ContainerControlledLifetimeManager。当然,我仍然可以手动将我的类型注册为单例,但如果我忘记了,应用程序将成功启动,而不是在启动时出现未处理的异常,并且一切似乎都正常工作。但最终会出现错误,可能非常微妙,难以诊断,因为存在一个类型的多个实例,这意味着是一个单例。所以我的问题是:有没有一种方法可以指定不同的默认生命周期管理器或完全禁用默认的自动解析行为并将容器限制为

c# - 使用静态工厂 Func<T> 为 ASP.NET 应用程序创建 "Ambient Context"(UserContext)

我发现几乎每个类(Controller、View、HTML帮助程序、服务等)我都需要当前登录的用户数据。所以我考虑创建一个“环境上下文”而不是直接注入(inject)IUserService或用户。我的方法看起来像那样。publicclassBootstrapper{publicvoidBoot(){varcontainer=newContainer();//thecalltoIUserService.GetUseriscachedperHttprequest//byusingadynamicproxycachingmechanism,thatalsohandlescaseswhere

c# - EntityFramework 测试初始化​​错误 : CREATE DATABASE statement not allowed within multi-statement transaction

我正在尝试构建一个快速测试,每次运行时都会删除并重新创建数据库。我有以下内容:[TestClass]publicclassPocoTest{privateTransactionScope_transactionScope;privateProjectDataSource_dataSource;privateRepository_repository=newRepository();privateconststring_cstring="DataSource=.;InitialCatalog=test_db;Trusted_Connection=True";[TestInitialize

c# - JWT 错误 IDX10634 : Unable to create the SignatureProvider C#

我正在尝试运行我的应用程序,但它因以下错误而卡住:System.NotSupportedExceptionHResult=0x80131515Message=IDX10634:UnabletocreatetheSignatureProvider.Algorithm:'[PIIishiddenbydefault.Setthe'ShowPII'flaginIdentityModelEventSource.cstotruetorevealit.]',SecurityKey:'[PIIishiddenbydefault.Setthe'ShowPII'flaginIdentityModelEve

c# - 如何使用 Simple injector、Repository 和 Context - code first

我正在尝试使用SimpleInjector创建我的存储库并在业务逻辑层中使用它(我也想使用PerWebRequest方法)。在DAL层我有:publicinterfaceIRepositorywhereT:class{voidAdd(Tentity);voidDelete(Tentity);voidDelete(intid);voidUpdate(Tentity);TGetById(intId);IQueryableAll();IEnumerableFind(Funcpredicate);}和:publicclassEFRepository:IRepository,IDisposabl

c# - 在 "CREATE TABLE permission denied in database"ASP.NET - MVC4 中列出表结果

我正在使用ASP.NETMVC4-c#连接到实时数据库并列出结果,但是当我查看页面时它返回以下错误:CREATETABLEpermissiondeniedindatabase'DatabaseName'.Description:Anunhandledexceptionoccurredduringtheexecutionofthecurrentwebrequest.Pleasereviewthestacktraceformoreinformationabouttheerrorandwhereitoriginatedinthecode.ExceptionDetails:System.Dat

c# - 当 new-able 使用 new T(),否则使用 default(T)

我正在研究C#泛型函数。错误时,如果泛型类型可以是new-able,返回newT(),否则返回default(T)。代码如下:privateTFunc(){try{//trytodosomething...}catch(Exceptionexception){if(Tisnew-able)//我知道对于那些使用newT()的人来说,它需要whereT:new()。这个问题是,如何在运行时判断这个? 最佳答案 您只需要检查该类型是否具有无参数构造函数。您可以通过以空类型作为参数调用Type.GetConstructor方法来实现。va

c# - 编译器错误 "Default parameter specifiers are not permitted"

下面是我的代码。publicclassPItem{publicStringcontent;publicintcount;publicintfee;publicintamount;publicstringdescription;//DefaultvaluespublicPItem(String_content="",int_count=0,int_fee=0,string_description="",int_amount=0){content=_content;count=_count这是在一个类里面。当我尝试运行程序时出现此错误:Defaultparameterspecifiersa

c# - 使用 Kendo Grid,如何更改工具栏中 "Create"按钮上的文字?

我使用的是KendoGrid,我添加了“创建”以内联添加记录。如何更改添加按钮上的措辞?目前显示为:“添加新记录”我想将其简化为只读“添加”并且我还想保留相同的图标。我的代码如下:$reports.kendoGrid({dataSource:dataSource,toolbar:["create"],...如有任何建议,我们将不胜感激。 最佳答案 执行此操作的方法是使用以下语法:$reports.kendoGrid({dataSource:dataSource,toolbar:[{name:"create",text:"Add"}]

c# - 为什么要使用 Create 方法而不是使用 "new"?

有什么优点,什么时候适合使用静态构造函数?publicclassMyClass{protectedMyClass(){}publicstaticMyClassCreate(){returnnewMyClass();}}然后通过创建类的实例MyClassmyClass=MyClass.Create();与仅拥有公共(public)构造函数并使用创建对象相反MyClassmyClass=newMyClass();如果Create方法返回类实现的接口(interface)实例,我可以看到第一种方法很有用……它将强制调用者创建接口(interface)实例而不是特定类型。