Open kianzarrin opened 4 years ago
Consult some C# dev who knows the best practices on this. I can give you a dozen of best practice ideas how to create an API but none of them are C#.
@dymanoid is usually an oracle or has good links on all things c#
For public API, the best practice is to use Semantic Versioning - the version format is major.minor.patch. You modify the major version when the public API gets breaking changes, i.e. compatibility. You modify the minor version to inform that there are new features, but the public API wasn't changed. You modify the patch version for bugfixes: neither new features, nor API changes. This is independent of the programming language in use.
InstanceProvider.GetXXX()
is a static factory and thus a kind of ServiceLocator
(other name: ServiceProvider
) anti-pattern (with slightly increased type safety). I wouldn't suggest using that.
Unfortunately, there is no neat way to use IoC in Unity-based games. Neither has Cities:Skylines any supporting features for that.
I would go with a single static factory that returns an interface-based facade for your API. Something like:
public static class TrafficManager
{
public static ITrafficManagerAccess GetAccess() { /* ... */ }
}
Then, you can organize your ITrafficManagerAccess
as you wish without forcing the clients to bind to any static
members of the API.
I assume that single static factory should be a part of main project (outside of public API) returning entirely new interface instance which would wrap other manager interfaces, right? Am I understand it right(based on our current API interfaces)? E.g.:
public interface ITrafficManagerAccess
{
ILaneArrowManager LaneArrowsManager(); //or `GetLaneArrowsManager`
ILaneConnectorManager LaneConnectorManager();
//...
}
Then we could safely change visibility of our manager interface implementations to internal (forcing access through that facade and public API)
Create a new Github project, a C# library call it TMPE API It will do this for known supported TMPE versions, and provide the serialization of call parameters, and deserialization of response (also known as "API access") to other mods who decide to use it.,
from #678