我建立一個應用程序具有以下結構:DDD在哪裏保留自定義異常(應用程序異常)?在基礎設施層?
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是一個配置節是我的應用層,因爲它使用它。我沒有看到其他方式將我的ImageSettings(應該保留在Infrastrucuture Layer中)轉移到基礎設施層,有人可以提供幫助嗎?
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"];
}
}
}
基礎設施參考應用。應用程序不參考基礎設施。我認爲這是正確的... –