CustomUtils Help

Service

프로젝트 바로 가기

코어 코드 바로 가기

구현 코드 바로 가기

Service Class Diagram
«Interface»IServicevoid Init()void Start()void Stop()Requiredbool IsService()void Refresh()void Remove()OptionalServiceList<Type> _cachedServiceTypeListReactiveDictionary<Type, IService> _serviceDicvoid Initialize()void StartService(...)void StopService(...)void RestartService(...)void RefreshService(...)void RemoveService(...)void GetService(...)Methods(...)«Attribute»ServiceAttributeHashSet<Enum> serviceTypeSetServiceAttribute()ServiceAttribute(params object[])ConstructorNewServiceMethods()Implementationbool IService.IsServing()void IService.Init()void IService.Start()void IService.Stop()void IService.Refresh()void IService.Remove()Internal CallAll Service can have at most one ServiceAttributeCall Initialize() using[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]Control10..*Annotate a class0..1

IService 상속 구현

  • IService 인터페이스 구현을 통한 통합 인스턴스 관리

  • IService를 상속 받은 모든 ClassService에서 통합 관리

public interface IService { protected internal bool IsServing() => false; protected internal void Init() { } protected internal void Start(); protected internal void Stop(); protected internal void Refresh() { } protected internal void Remove() { } }
Implement Member
IsServing()

Service 생성 후 매 Service.StartService() 에서 동작. 기본적으로 이미 시작한 Service 도 중복으로 시작할 수 있기 때문에 중복을 막기 위해선 오버라이딩 필요

Init()

Service 초기화 동작 구현 최초 생성 시 한 번 동작

Start()

Service 시작시 동작 구현 Service.StartService() 를 통해 동작

Stop()

Service 정지시 동작 구현 Service.StopService() 를 통해 동작

Refresh()

Service 새로 고침 동작 구현 Service.RefreshService() 를 통해 동작

Remove()

Service 제거시 동작 구현 Service.RemoveService() 를 통해 동작

Service 처리

코드 바로 가기

  • IService를 상속 받은 모든 Class를 관리 하며 Interface에 대한 개별 적인 접근을 차단 하고 Service를 통해서만 접근 하도록 제한.

  • 무분별한 인스턴스 확장을 막고 enum 정의를 통해 전체 혹은 일부분에 대한 통합 처리를 제공

  • 구현된 Classpublic으로 개별 구현된 Method에 대해서 만 접근이 가능

  • ex) StopWatchService.cs

[AttributeUsage(AttributeTargets.Class)] public sealed class ServiceAttribute : Attribute { public List<Enum> serviceTypeList = new(); public ServiceAttribute() => serviceTypeList.Add(DEFAULT_SERVICE_TYPE.NONE); public ServiceAttribute(params object[] serviceTypes) { foreach (var type in serviceTypes) { if (type is Enum enumType) { serviceTypeList.Add(enumType); } } } }
public static class Service { public static bool StartService(Type type) public static bool StartService<TService>() where TService : class, IService, new() public static bool StartService(Enum serviceType) }
public static class Service { public static bool StopService(Type type) public static bool StopService<TService>() where TService : class, IService, new() public static bool StopService(Enum serviceType) public static bool StopService(IService service) }
public static class Service { public static bool RestartService(Type type) public static bool RestartService<TService>() where TService : class, IService, new() public static bool RestartService(Enum serviceType) public static bool RestartService(IService service) }
public static class Service { public static bool RefreshService(Type type) public static bool RefreshService<TService>() where TService : class, IService, new() public static bool RefreshService(Enum serviceType) public static bool RefreshService(IService service) }
public static class Service { public static bool RemoveService<TService>() where TService : class, IService public static bool RemoveService(Enum serviceType) public static bool RemoveService(Type type) }
Last modified: 01 2월 2025