<commit_before>﻿using System;
using Castle.Windsor;
using SnittListan.Handlers;

namespace SnittListan.Events
{
	public static class DomainEvent
	{
		static DomainEvent()
		{
			ReturnContainer = DefaultReturnContainer;
		}

		public static Func<IWindsorContainer> ReturnContainer { get; set; }
		public static Action<IDomainEvent> RaiseAction { get; set; }

		public static void Raise<TEvent>(TEvent @event) where TEvent : IDomainEvent
		{
			if (RaiseAction != null)
			{
				RaiseAction(@event);
				return;
			}

			var container = ReturnContainer();
			var handlers = container.ResolveAll<IHandle<TEvent>>();

			foreach (var handle in handlers)
			{
				handle.Handle(@event);
				container.Release(handle);
			}
		}

		public static DomainEventReset TestWith(Action<IDomainEvent> raiseAction)
		{
			RaiseAction = raiseAction;

			return new DomainEventReset();
		}

		public static void Reset()
		{
			RaiseAction = e => { };
		}

		public static DomainEventReset Disable()
		{
			Reset();

			return new DomainEventReset();<commit_msg>Fixed default raise action<commit_after>﻿using System;
using Castle.Windsor;
using SnittListan.Handlers;

namespace SnittListan.Events
{
	public static class DomainEvent
	{
		static DomainEvent()
		{
			ReturnContainer = DefaultReturnContainer;
		}

		public static Func<IWindsorContainer> ReturnContainer { get; set; }
		public static Action<IDomainEvent> RaiseAction { get; set; }

		public static void Raise<TEvent>(TEvent @event) where TEvent : IDomainEvent
		{
			if (RaiseAction != null)
			{
				RaiseAction(@event);
				return;
			}

			var container = ReturnContainer();
			var handlers = container.ResolveAll<IHandle<TEvent>>();

			foreach (var handle in handlers)
			{
				handle.Handle(@event);
				container.Release(handle);
			}
		}

		public static DomainEventReset TestWith(Action<IDomainEvent> raiseAction)
		{
			RaiseAction = raiseAction;

			return new DomainEventReset();
		}

		public static void Reset()
		{
			RaiseAction = null;
		}

		public static DomainEventReset Disable()
		{
            RaiseAction = e => { };

			return new DomainEventReset();
{'fraction_non_alphanumeric': 0.09853842527109855, 'fraction_numerical': 0.0, 'mean_word_length': 3.7900677200902932, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6417306', 'n_tokens_mistral': 788, 'n_tokens_neox': 641, 'n_words': 159}