私は奇妙な問題があります。私はUnityをIOC/DIとして使用します。 LoggerServiceクラスのインスタンスを作成したいが、保護レベル ''のため、エラーアプリケーション'LoggerService.LogException(System.Exception、string、string)'にアクセスできません。私は、内部アクセス修飾子(クラスのアクセス修飾子なし)とコード内でアクセス可能な、Unityによって使用されるいくつかのクラスを持っています。それはなぜここで働いていないのですか?メソッドXXXは保護レベルのためにアクセスできません
私のコードは以下の通りです:
//console app executable module:
static void CommonOnUnhandledException(Exception exception, string messagePrefix)
{
var logger = Ioc.Resolve<LoggerService>(Config);
logger.LogException(exception, String.Empty, String.Empty);
Console.WriteLine(String.Format("{0} unhandled exception: {1}; {2}", messagePrefix, exception.Message, exception.StackTrace));
}
//library Services.dll
class LoggerService : ILoggerService
{
public LoggerService(AppConfiguration configuration)
{
...
}
public void LogException(Exception ex, string url = "", string messageContent = "")
{
...
}
}
//library services dll, started in console app
public static class ServicesModule
{
public static void Init(UnityContainer container)
{
// register all other ordinary types:
container.RegisterType<IIntelShopService, IntelShopService>(new ContainerControlledLifetimeManager());
container.RegisterType<IBackendService, BackendService>(new ContainerControlledLifetimeManager());
container.RegisterType<IIntelODataService, IntelODataService>(new ContainerControlledLifetimeManager());
container.RegisterType<ILoggerService, Log4NetLoggerService>(new ContainerControlledLifetimeManager());
container.RegisterType<IPerformanceTrackerService, PerformanceTrackerService>(new ContainerControlledLifetimeManager());
}
}
LoggerServiceはデフォルトでは内部であり、dll内でのみアクセス可能です。 – Keppy
IMはIOCの問題について質問していますが、IOCのない解決策はありません! –