chef 3745 Posted April 17, 2020 Share Posted April 17, 2020 (edited) Don't laugh at me! I just figured this out and it changes the world! public class MyService : MyServiceHandler, IService { private IJsonSerializer JsonSerializer { get; } //Sending objects to the base inherited class! public MyService(ITVSeriesManager series, ILibraryManager libraryManager, ISessionManager sessionManager, ILogManager logManager, IUserManager userManager, IJsonSerializer json, IUserDataManager userData, IDeviceManager device) : base(json, logManager, sessionManager, libraryManager, userManager, series, userData) //<--there { JsonSerializer = json; } public object Post(Request data) { var myRequestDataSerialized = JsonSerializer.DeserializeFromStream<MyRequestDto>(data.RequestStream); return GetResponse(myRequestDataSerialized ); } } public class MyServiceHandler { private ILogger Logger { get; } //Because this class needed these object, they where passed into the class through the ":base()" of MySerivce constructor protected MyRequestHandler(IJsonSerializer jsonSerializer, ILogManager log, ISessionManager sessionManager, ILibraryManager libraryManager, IUserManager userManager, ITVSeriesManager tvSeriesManager, IUserDataManager userData) : base(jsonSerializer, log, sessionManager,libraryManager,userManager, tvSeriesManager, userData) { Logger = log.GetLogger(Plugin.Instance.Name); } protected string GetResponse(MyRequestDto myRequestData) { Logger.Info(myRequestData.type); //Do something with my request data } } You can pass the objects needed into other classes which are inherited with ":base()" in the constructor, instead of 'newing them up' Base Classes! Son of a...! {faceplam} i said don't laugh at me! Edit: wait a minute... is that the "Stack" that everyone talks about? Edited April 17, 2020 by chef 1 Link to comment Share on other sites More sharing options...
mickle026 400 Posted April 19, 2020 Share Posted April 19, 2020 (edited) Thanks for sharing this, Although it was staring you in the face, and I kinda saw it ...you explanation is what makes it clearer for me. public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer) { Instance = this; } I kinda got this, not fully understanding it though... but missing other stuff that should be much easier, still learning c# ..... this information will probably be needed at some point Edited April 19, 2020 by mickle026 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now