カスタム追跡参加者があります:
public class ErsTrackingParticipant : TrackingParticipant, IErsTrackingParticipant
{
private readonly INHibernateRepository<ErsTrackingRecord> _ersTrackingRecordRepository;
public ErsTrackingParticipant(INHibernateRepository<ErsTrackingRecord> ersTrackingRecordRepository)
{
this._ersTrackingRecordRepository = ersTrackingRecordRepository;
}
protected override void Track(TrackingRecord record, TimeSpan timeout)
{
ErsTrackingRecord ersTrackingRecord = TrackingCommand.GetTrackingRecord(record);
this._ersTrackingRecordRepository.Save(ersTrackingRecord);
}
}
public interface IErsTrackingParticipant
{
}
およびワークフロー ホスト ヘルパー:
public class WorkflowHostHelper: IWorkflowHostHelper
{
private WorkflowApplication _workflowApplication;
AutoResetEvent _instanceUnloaded = new AutoResetEvent(false);
private IErsTrackingParticipant _ersTrackingParticipant;
private bool _isCompleted = false;
public string InstanceStoreConnectionString { get { return ConfigurationManager.AppSettings["InstanceStoreConnectionString"]; } }
public WorkflowHostHelper(IErsTrackingParticipant ersTrackingParticipant)
{
_ersTrackingParticipant = ersTrackingParticipant;
}
public void Initialize(Activity workflowType)
{
_workflowApplication = new WorkflowApplication(workflowType);
TrackingProfile trackingProfile = new TrackingProfile() { Name = "TroubleshootingProfile", ActivityDefinitionId = "*" };
trackingProfile.Queries.Add(new WorkflowInstanceQuery { States = { "*" } });
trackingProfile.Queries.Add(new ActivityStateQuery { States = { "*" } });
trackingProfile.Queries.Add(new ActivityScheduledQuery());
trackingProfile.Queries.Add(new BookmarkResumptionQuery() { Name = "*" });
_workflowApplication.Extensions.Add(_ersTrackingParticipant);
SynchronizationContext synchronizationContext = SynchronizationContext.Current;
_workflowApplication.SynchronizationContext = synchronizationContext;
_workflowApplication.InstanceStore = new SqlWorkflowInstanceStore(InstanceStoreConnectionString);
_workflowApplication.PersistableIdle = (e) =>
{ return PersistableIdleAction.Persist; };
_workflowApplication.Completed = (e) =>
{
_isCompleted = true;
_instanceUnloaded.Set();
};
_workflowApplication.Idle = (e) =>
{ _instanceUnloaded.Set(); };
} //Rest ommiitted...
リポジトリがデータベースに保存しようとすると、次のエラーが発生します。
'((SharpArch.NHibernate.NHibernateRepositoryWithTypedId<EmployeeRequestSystem.Domain.ErsTrackingRecord,int>)(this._ersTrackingRecordRepository)).Session' threw an exception of type 'System.NullReferenceException'
SharpArch.NHibernate.Contracts.Repositories.INHibernateRepositoryWithTypedId<T,TId>.DbContext = {SharpArch.NHibernate.DbContext}
ワークフロー アクティビティでは、コンテキストを参照し、次のようなサービス ロケーターを使用できます。
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.AddDefaultExtensionProvider<INHibernateRepository<AuthorisationRequest>>(
() => new NHibernateRepository<AuthorisationRequest>());
}
...
protected override void Execute(CodeActivityContext context)
{
var authorisationRequestRepoistory = context.GetExtension<INHibernateRepository<AuthorisationRequest>>();
ErsTrackingParticipant に正しいコンテキストを取得するにはどうすればよいですか?