Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Code Consolidation Architecture

KGComputers

New member
Joined
Dec 7, 2005
Messages
1,949
Hello,

Our team recently discussed to consolidate code so that multiple consumers can easily utilize the same code base since our projects are growing in numbers. At present we have 40+ schedule task service projects running on a server for different contracts/clients. But the numbers may increase soon.

The goal for the architecture is the code can be consumed by non windows and mobile application and easy to maintain. These include models and functions per contract written in .NET C#.

Now, we have three options:
1. dll via nuget
2. WCF hosted in IIS
3. ASPX or asmx Service

Are there any alternative solutions available aside from the aformentioned above? Let me know also the pro(s) and con(s) based from your experiences on these.

Regards,

kgc
 

PlausiblyDamp

New member
Joined
Dec 8, 2016
Messages
1,190
Without knowing any of the specifics, if you are looking for a way of hosting a service then you might want to also consider a WebAPI based app (more of a json / RESTful approach) as an alternative to WCF or a Webservice.

A nuget packaged Dll would really only be useful to other .Net languages and would not really be suitable for a cross platform solution unless you were also using something like Xamarin as a mobile technology.
 
Joined
May 20, 2005
Messages
104,556
ASP.NET Web API is basically MVC without an actual V, i.e. you just serve data rather than views. Particularly if you already use MVC, Web API is a no-brainer.
 

NeedSomeAnswers

Superbly Moderated
Joined
Jun 4, 2002
Messages
2,610
Thanks. will definitely do some research on Web API.

Web API Is Really easy to use, here is a simple example of a method we use in one of our apps in C# ( I have removed our custom error-handling)

Something to note if you've used MVC you will be familiar with but if not the _userRepository interface has been injected into the class

Code:
[Route("GetUser/{tenantId:int}/{tenantName}/{userName}")]
        [HttpGet]
        public Result<User> GetUser(int tenantId, string tenantName, string userName)
        {
            Result<User> result = new Result<User>();

            try
            {
                result = _userRepository.GetUser(tenantId, tenantName, userName);
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }

In this particular app we are using Entity framework so the data call looks like this -

Code:
public Result<User> GetUser(int tenantId, string tenantName, string userName)
        {
            var result = new Result<User>();

            try
            {
                using (WebBundleDbEntities webBundleContext = Common.GetConnection(tenantId))
                {
                    var userDetails = webBundleContext.csp_web_GetUserFromSystemName(userName).FirstOrDefault();

                    if (userDetails != null)
                    {
                        var data = new User()
                        {
                            Id = userDetails.ID,
                            Name = userDetails.Name,
                            SystemName = userDetails.System_Name,
                            TenantId = tenantId,
                            TenantName = tenantName
                        };

                        result.Data = data;
                        result.IsSuccess = true;
                    }
                    else
                        result.Message = Resource.msgUserDoesNotExist;
                }
            }
            catch (Exception ex)
            {
               
            }

            return result;
        }

We are using a Model called User which is just a class with properties in it and then a class called Result which encapsulates all our return objects and allows us to return some other information alongside the data such as if the call was successful and any error messages

Code:
public class Result<TEntity>
    {
        public Result()
        {
            IsSuccess = false;
            Message = string.Empty;
            Count = 0;
        }

        public bool IsSuccess { get; set; }

        public string Message { get; set; }

        public TEntity Data { get; set; }

        public int Count { get; set; }

        public Exception Exception { get; set; }
    }
 
Top