【发布时间】:2020-08-30 04:34:35
【问题描述】:
我正在构建一个具有以下架构的应用程序:
UI - 应用程序 - 领域 - 基础架构
我有一个需要使用自定义异常的应用层。我将这些自定义异常保存在哪里?在基础设施层?问题是我的应用层没有对基础设施层的引用。
正确的方法是什么?
更新:
这是我在应用层中引发异常的代码:
public void InsertNewImage(ImagemDTO imagemDTO)
{
if (isValidContentType(imagemDTO.ImageStreamContentType))
{
string nameOfFile = String.Format("{0}{1}", Guid.NewGuid().ToString(), ContentTypeHelper.GetExtension(imagemDTO.ImageStreamContentType));
string path = String.Format("{0}{1}", ImageSettings.PathToSave, nameOfFile);
_fileService.SaveFile(imagemDTO.ImageStream, path);
Imagem imagem = new Imagem()
{
Titulo = imagemDTO.Titulo,
Descricao = imagemDTO.Descricao,
NomeArquivo = nameOfFile
};
_imagemRepository.Add(imagem);
_dbContext.SaveChanges();
} else
{
throw new WrongFileTypeException(String.Format("{0} is not allowed.", ContentTypeHelper.GetExtension(imagemDTO.ImageStreamContentType)));
}
}
甚至 ImageSettings 是 ConfigurationSection 在我的应用程序层中,因为它使用它。我没有看到其他方法可以将我的 ImageSettings(应该保留在基础设施层中)转移到基础设施层,有人可以帮忙吗?
public class ImageSettings : ConfigurationSection
{
/// <summary>
/// Caminha onde será salvo as imagens
/// </summary>
[ConfigurationProperty("pathToSave", IsRequired = true)]
public string PathToSave
{
get { return (string)this["pathToSave"]; }
set { this["pathToSave"] = value; }
}
/// <summary>
/// Extensões permitidas pra upload
/// </summary>
[ConfigurationProperty("allowedExtensions", IsRequired = true)]
public string AllowedExtensions
{
get { return (string)this["allowedExtensions"]; }
set { this["allowedExtensions"] = value; }
}
/// <summary>
/// Tamanho das imagens
/// </summary>
[ConfigurationProperty("imageSize")]
public ImageSizeCollection ImageSize
{
get
{
return (ImageSizeCollection)this["imageSize"];
}
}
}
【问题讨论】: