我正在使用Caliburn.Micro和Autofac开发应用程序.
在我的组合根目录中,我现在面临着Autofac的问题:我必须将全局使用的IEventAggregator注入我的FirstViewModel,以及第二个IEventAggregator,它必须仅由FirstViewModel及其子项使用.
我的想法是将第二个注入Owned<IEA>,并且它起作用,容器提供了IEA的不同实例.
public FirstViewModel(
IEventAggregator globalEA,
IEventAggregator localEA,
Func<IEventAggregator, SecondViewModel> secVMFactory) {}
Run Code Online (Sandbox Code Playgroud)
当我必须向SecondViewModel提供事件聚合器时,问题就出现了.
要创建SecondViewModel,我使用工厂方法Func<IEA, SecondVM>.SecondViewModel的构造函数如下:
public SecondViewModel(IEventAggregator globalEA, IEventAggregator localEA) {}
我希望容器注入第一个作为注册的容器,第二个将是IEA参数Func<IEA, SecVM>.
这是我在容器中注册的功能:
builder.Register<Func<IEventAggregator, SecondViewModel>>(
c =>
(ea) =>
{
return new SecondViewModel(
c.Resolve<IEventAggregator>(),
ea);
}
);
Run Code Online (Sandbox Code Playgroud)
但当它被FirstViewModel我调用时,我得到以下错误:
Autofac.dll中出现"System.ObjectDisposedException"类型的异常,但未在用户代码中处理
附加信息:此解析操作已结束.使用lambdas注册组件时,无法存储lambda的IComponentContext'c'参数.相反,要么从'c'再次解析IComponentContext,要么解析基于Func <>的工厂以从中创建后续组件.
我无法理解问题出在哪里,你能帮帮我吗,我错过了什么?
谢谢.
我刚开始使用Caliburn.Micro.
我正在尝试引导我的简单示例解决方案,将ShellView(usercontrol)放在Test.App程序集中,将ShellViewModel放在Test.ViewModel程序集中.
我得到的是一个窗口,其中包含以下文本:"无法找到Caliburn.Test.ViewModel.ShellViewModel的视图".
但是,如果我将ViewModel移动到.App程序集,它可以很好地工作.
这是Caliburn.Micro.Test程序集中的Bootstraper(可执行文件):
namespace Caliburn.Micro.Test
{
public class AppBootstrapper : BootstrapperBase
{
SimpleContainer container;
public AppBootstrapper()
{
this.Start();
}
protected override void Configure()
{
container = new SimpleContainer();
this.container.Singleton<IWindowManager, WindowManager>();
this.container.Singleton<IEventAggregator, EventAggregator>();
this.container.PerRequest<IShell, ShellViewModel>();
}
protected override object GetInstance(Type service, string key)
{
var instance = this.container.GetInstance(service, key);
if (instance != null)
return instance;
throw new InvalidOperationException("Could not locate any instances.");
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return this.container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
this.container.BuildUp(instance); …Run Code Online (Sandbox Code Playgroud) 我有一个Styles.xaml该集团很多ResourceDictionary的内线一个MergedDictionary.
我导入了Styles.xaml UserControl.Resources
<UserControl.Resources>
<ResourceDictionary Source="Dictionaries\Styles.xaml" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试添加转换器时
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionaries\Styles.xaml" /> <--! Exception -->
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
它提升了
ArgumentNullException:值不能为null.
参数名称:item
将转换器包装在另一个内部MergedDictionary无效.
我怎么解决这个问题?
谢谢你们!
我最终弄清楚了:它Exception是在.xaml文件中引发的,但是Visual Studio没有提供足够的信息来找到错误的行.
以下代码确实有效.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionaries\Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud) 我无法理解简单裸露之间的区别
Public ClassName() {}
Run Code Online (Sandbox Code Playgroud)
和
Public ClassName() : this(null) {}
Run Code Online (Sandbox Code Playgroud)
我知道只有当我有一个+1超载的ctor 我才能使用它,但我无法理解defining the parameterless constructor这种方式的优点.
就像标题中一样,我想知道WPF样式中的IsMouseOver和IsHighlighted属性触发器之间有什么区别。
有人知道吗?
如果我使用以下方法在 Visual Studio 中创建一个新的 ASP.NET Core Web API + Angular 项目dotnet new angular,它会创建一个.NET 5项目,在 ClientApp 中包含一个新的Angular 8.2项目。
如果我F5这样做,一切正常。
但是我想使用 Angular 11 项目,所以我擦除了 ClientApp 内容,在那里打开一个终端,然后:ng new <app-name> --directory ./那里。
项目创建,F5项目启动,但在每次启动时,调试控制台中都会出现这两行:
Microsoft.AspNetCore.SpaServices: 错误: - 生成浏览器应用程序包... Microsoft.AspNetCore.SpaServices: 错误: ?êÜ 浏览器应用程序包生成完成。
我做了很多尝试:合并来自 previous tsconfig.json、 from angular.json、 的值launchSettings.json,但没有解决它。
相反,如果我ng serve从 ClientApp 目录启动一个,它可以正常工作。
Visual Studio 和 Angular 的 CLI 之间是否存在一些不兼容?谢谢大家!
你可以在这段代码中澄清为什么:
private Dictionary<Type, Type> viewTypeMap = new Dictionary<Type, Type>();
public void ShowView<TView>(ViewModelBase viewModel, bool showDialog = false)
where TView : IView
{
var view = Activator.CreateInstance(viewTypeMap[typeof(TView)]);
(IView)view.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
"只有赋值,调用,递增,递减和新对象表达式才能用作语句."
IView定义了ShowDialog()方法.
为什么存储库的.Add方法通常实现为接受要添加的实体实例,并且.Id已经“设置”(尽管可以通过反射再次设置),这应该是存储库的责任?
实现它不是更好.CreateAndAdd吗?
例如,给定一个Person实体:
public class Person
{
public Person(uint id, string name)
{
this.Id = id;
this.Name = name;
}
public uint Id { get; }
public string Name { get; }
}
Run Code Online (Sandbox Code Playgroud)
为什么存储库通常实现为:
public interface IRpository<T>
{
Task<T> AddAsync(T entity);
}
Run Code Online (Sandbox Code Playgroud)
而不是:
public interface IPersonsRpository
{
Task<Person> CreateAndAddAsync(string name);
}
Run Code Online (Sandbox Code Playgroud) domain-driven-design data-access-layer ddd-repositories repository-pattern
我正在构建一个Window,但我注意到WindowChrome的这种奇怪的行为(在.NET FW 4.0中,来自外部的Microsoft.Windows.Shell dll).
我使用AllowTransparency = true和WindowStyle = None设置WindowChrome.
如果我设置WindowChrome的ResizeBorderThickness <= 7一切都很完美,但如果我这样做
ResizeBorderThickness="8"
或者更多,当窗口最大化时,我无法将其从屏幕上边缘附近的最后一个顶部像素拖动,并且对于每个超过7的+1,我必须开始从边缘向下拖动1个像素.
这很烦人,因为它在关闭窗口时禁用了常见的行为,迫使我将其设置为7或更低.
有人可以解释我这种行为吗?
谢谢!
如果我有一个定义控件模板的样式,并且我有一个控件,让我们说一个按钮,有没有办法从样式控件后面的代码访问按钮?
感谢你们!=)
我目前正在尝试实现一个简单的博客应用程序以用于学习目的。它在 DDD 架构内。
我关心的是如何实现通用存储库模式。
你们能否就我是否正确实施存储库提出您的想法。
这是我第一次使用通用存储库,看起来我根本没有使用它。
下面显示了我的用户存储库的实现。
非常感谢
public interface IRepository<TEntity> where TEntity : class
{
TEntity GetById(int id);
IEnumerable<TEntity> GetAll();
IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);
void Add(TEntity entity);
void Update(TEntity entity);
void Remove(TEntity entity);
}
//Implementation of Generic Repo
using BA.Infrastructure.Data.Context;
using BA.Infrastructure.Data.Interfaces.Helpers;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace BA.Infrastructure.Data.Repositories.Helpers
{
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
{
protected readonly BlogDbContext _context;
public Repository(BlogDbContext context)
{
_context = context;
}
public TEntity …Run Code Online (Sandbox Code Playgroud) c# ×4
wpf ×4
.net ×3
xaml ×3
mvvm ×2
styles ×2
.net-4.0 ×1
.net-5 ×1
activator ×1
angular ×1
asp.net-core ×1
autofac ×1
code-behind ×1
constructor ×1
dictionary ×1
generics ×1
ismouseover ×1
parameters ×1
triggers ×1
unit-of-work ×1